【发布时间】:2016-10-22 12:39:07
【问题描述】:
我开发了一个 Cordova Phaser 游戏。它可以在 Android 和 iOS 设备上运行。
游戏有七个关卡,每个关卡都有多个精灵(背景、玩家)和组(子弹、敌人)。
在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)等等。
在浏览器中它运行良好,但在移动内存中每个级别都会翻倍,应用程序最终会崩溃。如何避免这个内存问题?
【问题讨论】:
标签: javascript cordova phaser-framework