我找到了一些garbageCollector 的代码示例,用于删除屏幕外的精灵,但它仅适用于旧版本的Phaser。
如何将此代码从 v1.1.5 重建到 v2.0.4?
错误代码:
Phaser v2.0.3 - WebGL - WebAudio http://phaser.io ♥♥♥ phaser.min.js:8 未捕获的类型错误:无法读取 null(索引)的属性“重置”:34 add_cloud(索引):34 b.Timer.update phaser.min.js:12 b.Time.update phaser.min.js:12 b.Game.update phaser.min.js:8 b.RequestAnimationFrame.updateRAF phaser.min.js:11 window.requestAnimationFrame.forceSetTimeOut._onLoop phaser.min.js:11
适用于旧版本(v1.1.5)的代码:
<script>
var game = new Phaser.Game(800, 480, Phaser.AUTO, '', { preload: preload, create: create, update: update });
var clouds;
var cloud_dummy;
function preload() {
game.load.image('mario_cloud', 'mario_cloud.png');
}
function create() {
clouds = game.add.group();
clouds.enableBody = true;
clouds.createMultiple( 6, 'mario_cloud');
timer_shit = game.time.events.loop(1500, add_cloud, this);
}
function update() {
}
function add_cloud() {
cloud_dummy = clouds.getFirstDead();
cloud_dummy.reset(800, 100);
cloud_dummy.body.velocity.x -= 150;
cloud_dummy.body.immovable = true;
cloud_dummy.outOfBoundsKill = true;
}
</script>