【发布时间】:2016-10-22 21:18:22
【问题描述】:
//编辑
我想在切换状态和返回状态后保存健康,硬币,乐趣值。
我创建了游戏对象/数组:
game.yourGameData = {};
game.yourGameData.health = 100;
game.yourGameData.coin = 100;
game.yourGameData.fun = 100;
接下来我定义参数宠物的值:
//设置健康
var health, fun, coin;
health = this.game.yourGameData.health;
fun = this.game.yourGameData.fun;
coin = this.game.yourGameData.coin;
//custom properties of the pet
this.pet.customParams = {health, fun, coin};
并且值显示没有错误。 现在我通过函数打开子游戏:
showtry: function()
{
this.game.state.start('brick_destro_game');
},
当我完成子游戏并切换回主状态时,健康值为 100。
状态切换功能:
clickOnActionExit: function()
{
this.game.state.start('GameState');
},
我想看的: 宠物盯着100生命值,接下来他什么都不吃。生命值降至 70。 我将状态切换到子游戏并播放。我完成游戏并回到主要状态。 宠物应该有 70 生命值,但它会重置为 100。
【问题讨论】:
-
你在哪里设置
yourGameData对象?如果设置在 GameState 状态,每次启动都会重置 -
检查文件:游戏我只是添加到帖子中
-
好的,你有
this.pet...但是它有定义吗? start 方法内的状态?this是game还是状态或其他什么? -
pet 在创建函数中定义。 this.pet = .......... 我将在其他地方定义它。我会检查;D
-
好的,我把宠物定义的地方改成“全局变量”。还是一样。
标签: javascript android phaser-framework