2014-02-27 118 views
15

[Chrome v32]用pixi.js繪製一個矩形

如何用PIXI.js庫繪製一個基本的RED矩形?

我想這(不工作)

var stage = new PIXI.Stage(0xFFFFFF); 
var renderer = PIXI.autoDetectRenderer(400, 300); 
document.body.appendChild(renderer.view); 
renderer.render(stage); 
var rect = new PIXI.Rectangle(100, 150, 50, 50); 
stage.addChild(rect); 

錯誤:

Uncaught TypeError: Object [object Object] has no method 'setStageReference'

回答

7

Geometries are not renderable, they are for doing geometric calculations.

Source @xerver

所以我們必須使用PIXI.Graphics()

31

現在可以參見提供的鏈接:http://www.goodboydigital.com/pixi-webgl-primitives/

var graphics = new PIXI.Graphics(); 

graphics.beginFill(0xFFFF00); 

// set the line style to have a width of 5 and set the color to red 
graphics.lineStyle(5, 0xFF0000); 

// draw a rectangle 
graphics.drawRect(0, 0, 300, 200); 

stage.addChild(graphics);