我基本上想在每次调用函数时更改字符的位置。
这就是我调用函数的地方,
timer = game.time.create(false);
timer.add(2000, this.toggleCurrentCharacter, this);
timer.start();
它调用的我的函数如下所示,
toggleCurrentCharacter:function() {
var characterArr = [characterA, characterB, characterC];
var characterPosArr = [LEFT_CENTER, CENTER, RIGHT_CENTER];
characterA.alignIn(columnLeft, Phaser.CENTER);
characterB.alignTo(columnLeft, Phaser.RIGHT_CENTER);
characterC.alignTo(columnLeft, Phaser.LEFT_CENTER);
console.log("Testing");
timer.add(2000, this.toggleCurrentCharacter, this);
}
timer.add
只是确保我的函数无限运行。
每次函数运行时,我都想更改 Sprite 的对齐方式,因此您会看到 RIGHT_CENTER
、CENTER
等。
我认为我需要一个数组来迭代,但我无法理解和弄清楚每次调用该函数时,Phaser.RIGHT_CENTER
将如何迭代,例如,下次我调用函数 Phaser.RIGHT_CENTER
现在看起来像 Phaser.CENTER
等等。
谢谢
最佳答案
您可以编写一个名为旋转的函数:
function rotate(array) {
return array.splice(1).concat(array);
}
或任意数量的其他排列:
function rotate(array) {
return array.concat(array.shift());
}
关于javascript - 每次调用 JavaScript 函数时移至数组中的下一项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43182310/