空白的原因是您的某些动画没有开始。原因就在这一行:
new Tween(square, 'position.y', square._y, Math.floor(Math.random() * 80), true);
查看 Tween.js 的函数定义,我看到了:
function Tween(object, property, value, frames, autostart)
第四个参数是frames。我假设这是完成动画所需的帧数。
那么你的 Math.floor 函数有时会返回零,这意味着动画将没有帧并且不会开始!
您可以改用 math.ceil() 来解决此问题。这样动画总是至少有 1 帧:
new Tween(square, 'position.y', square._y, Math.ceil(Math.random() * 80), true);
现在,至于性能,我建议设置不同的...
动画所有这些图形对象是非常密集的。我的建议是绘制一个红色正方形,然后使用 RenderTexture 从正方形生成位图。然后你可以将 Sprites 添加到舞台上,它们在制作动画时表现得更好。
//Cretae a single graphics object
var g = new PIXI.Graphics();
g.beginFill(0xFF0000).drawRect(0, 0, 2, 2).endFill();
//Render the graphics into a Texture
var renderTexture = new PIXI.RenderTexture(RENDERER, RENDERER.width, RENDERER.height);
renderTexture.render(g);
for (var i = 0; i < CONFIG.rows; i++) {
for (var j = 0; j < CONFIG.cols; j++) {
var x = j * 4;
var y = i * 4;
//Add Sprites to the stage instead of Graphics
var PARTICLE = new PIXI.Sprite(renderTexture);
PARTICLE.x = x;
PARTICLE.y = -200;
PARTICLE._y = H - y;
STAGE.addChild(PARTICLE);
}
}
此链接将包含更多 RenderTexture 示例:
http://pixijs.github.io/examples/index.html?s=demos&f=render-texture-demo.js&title=RenderTexture