【发布时间】:2017-06-14 11:54:57
【问题描述】:
我在函数调用中添加了一些精灵,如下所示:
moveSlotMachineIn() {
var comboBaseTweenIn = this.game.add.tween(this.comboBase).to({x: 10}, 2000, "Quart.easeOut", 3000);
var comboTopTweenIn = this.game.add.tween(this.comboTop).to({x: 10}, 2000, "Quart.easeOut", 3000);
var comboMaskTweenIn = this.game.add.tween(this.comboMask).to({x: 10}, 2000, "Quart.easeOut", 3000);
var arrowGrpTweenIn = this.game.add.tween(this.arrowSlotGroup).to({x: 200}, 2000, "Quart.easeOut", 3000);
}
这是可行的,并且在函数调用时,精灵确实会从左向右滑入。
现在,我还应该将对象滑出。这是通过计时器完成的,因此它不会立即滑出,如下所示:
this.game.time.events.add(3000, this.comboLayer.moveSlotMachineOut, this);
调用这个函数:
moveSlotMachineOut() {
console.log(this.comboBase);
var comboBaseTweenOut = this.game.add.tween(this.comboBase).to({x: 1600}, 2000, "Quart.easeOut", 3000);
var comboTopTweenOut = this.game.add.tween(this.comboTop).to({x: 1600}, 2000, "Quart.easeOut", 3000);
var comboMaskTweenOut = this.game.add.tween(this.comboMask).to({x: 1600}, 2000, "Quart.easeOut", 3000);
var arrowGrpTweenOut = this.game.add.tween(this.arrowSlotGroup).to({x: 1600}, 2000, "Quart.easeOut", 3000);
}
但由于某种原因,我收到以下错误:
phaser.js:64795 Uncaught TypeError: Cannot read property 'x' of 未定义
指向this.comboBase 的moveSlotMachineOut()。同样奇怪的是,上述函数中的console.log 位返回undefined。
这是我对this.comboBase的初始化:
this.comboBase = this.game.add.sprite(this.x -10, this.y, 'ui');
this.comboBase.anchor.set(0.5, 0.5);
this.comboBase.frameName = 'ui_specialBase.png';
其余的有些相似。据我所知,我没有清除变量的值,所以我不确定发生了什么。
什么可能导致变量未定义?补间有什么作用吗?
【问题讨论】:
标签: javascript phaser-framework