我發現了一些用於刪除屏幕外精靈的garbageCollector的代碼示例,但它只能在老版本的Phaser中工作。
如何重建此代碼從v1.1.5到v2.0.4?
錯誤代碼:Phaser,刪除outOfBounds sprite
Phaser v2.0.3 - WebGL - WebAudio http://phaser.io ♥♥♥ phaser.min.js:8 Uncaught TypeError: Cannot read property 'reset' of null (index):34 add_cloud (index):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
代碼:
<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>
現場演示做這樣的事情:HTTP://koryato.yomu .ru/tests/ – Rincew1nd
我找到了一個解決方案。 只需添加字符串cloud_dummy.checkWorldBounds = true; – Rincew1nd