0
我開發了一個Cordova Phaser遊戲。它運行在Android和iOS設備上。如何避免在使用Cordova的Phaser遊戲中使用高內存?
遊戲有七個等級,每個等級都有一些精靈(背景,玩家)和羣體(子彈,敵人)。
在preload
功能,我已經加載的所有圖像和atlasJSONHash
function preload(){
game.load.atlasJSONHash('anim', 'anim.png', 'anim.json');
//and so on
}
function create(){
var star = game.add.sprite(160, 32, 'level1bg');
star.x = 0;
star.y = 0;
star.height = game.height;
star.width = game.width;
bullets = game.add.group();
bullets.enableBody = true;
bullets.physicsBodyType = Phaser.Physics.ARCADE;
bullets.createMultiple(30, 'bullet');
bullets.setAll('anchor.x', 0.5);
bullets.setAll('anchor.y', 1);
bullets.setAll('outOfBoundsKill', true);
bullets.setAll('checkWorldBounds', true);
//and so on
}
function startlevel(level)
{
var star = game.add.sprite(160, 32, 'level1bg');
star.x = 0;
star.y = 0;
star.height = game.height;
star.width = game.width;
bullets = game.add.group();
bullets.enableBody = true;
bullets.physicsBodyType = Phaser.Physics.ARCADE;
bullets.createMultiple(30, 'bullet');
bullets.setAll('anchor.x', 0.5);
bullets.setAll('anchor.y', 1);
bullets.setAll('outOfBoundsKill', true);
bullets.setAll('checkWorldBounds', true);
//and so on
}
當關卡結束我叫startlevel(2)
等。
在瀏覽器中運行良好,但在移動內存中每個級別都會翻倍,應用程序最終會崩潰。我如何避免這種內存問題?