【发布时间】:2022-08-03 12:10:40
【问题描述】:
玩家必须接住鸡蛋,所以鸡蛋(由gameState.eggs = this.physics.add.group();制成)在坡道上具有一定的velocity,但是一旦它们离开坡道,我想自动将setVelocity()变为一个x 坐标为 0,而不是只在屏幕上拍摄。
这是我的鸡蛋生成功能:
function eggGen() {
let num = Math.random();
let xCoord, yCoord, eggDirection, eggAnimation, velocityX
if (num < .5) {
xCoord = 100;
eggDirection = \'eggLeft\';
eggAnimation = \'rollingLeft\'
velocityX = this.velocityX;
if (num < .25) {
yCoord = 232;
} else {
yCoord = 382;
}
} else {
xCoord = 700;
eggDirection = \'eggRight\';
eggAnimation = \'rollingRight\';
velocityX = -(this.velocityX)
if (num < .75) {
yCoord = 232;
} else {
yCoord = 382;
}
}
let egg = gameState.eggs.create(xCoord, yCoord, eggDirection).setVelocity(velocityX, this.velocityY).setScale(.6);
if (egg.x > 220 && egg.x < 580) {
egg.setVelocity(0, this.velocityY);
}
egg.anims.play(eggAnimation);
}
最后一个条件是我希望做的魔术,但它没有做任何事情。澄清一下,eggGen 函数在 this.time.addEvent(); 内部调用
标签: javascript phaser-framework