0
我有一些精靈,我補間在一個函數調用,就像這樣:移相器:在吐溫不同功能設定對象爲undefined
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 undefined
這是指向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';
他們其餘的有幾分相似。據我所知,我不清楚變量的值,所以我不確定發生了什麼。
什麼可能導致變量未定義?補間是否做任何事情?