单击所需按钮时,球无法正常工作,Phaser 3
the ball does not function as desired when clicked on the desired button, Phaser 3
代码好像有问题,我加这段代码的时候一键减速一键加速,
this.downButton = this.add.image(80, 530, 'up-bubble').setInteractive();
this.upButton = this.add.image(230, 530, 'down-bubble').setInteractive();
this.input.on('gameobjectup', function (pointer, gameobject) {
if (gameobject === this.downButton && this.spinSpeed > 0)
{
this.spinSpeed -= 0.1;
}
else if (gameobject === this.upButton && this.spinSpeed < 9.9)
{
this.spinSpeed += 0.1;
}
});
但是,当我在 generateBalls() 之间添加这段代码时,它根本不起作用,它不起作用,
generateBalls() {
const hitArea = new Phaser.Geom.Rectangle(0, 0, 32, 32);
const hitAreaCallback = Phaser.Geom.Rectangle.Contains;
const circle = new Phaser.Geom.Circle(400, 300, 220);
const balls = this.add.group(null, {
key: 'balls',
frame: [0, 1, 5],
repeat: 5,
setScale: { x: 3, y: 3 },
hitArea: hitArea,
hitAreaCallback: hitAreaCallback,
});
this.downButton = this.add.image(80, 530, 'up-bubble').setInteractive();
this.upButton = this.add.image(230, 530, 'down-bubble').setInteractive();
this.input.on('gameobjectup', function (pointer, gameobject) {
if (gameobject === this.downButton && this.spinSpeed > 0)
{
this.spinSpeed -= 0.1;
}
else if (gameobject === this.upButton && this.spinSpeed < 9.9)
{
this.spinSpeed += 0.1;
}
});
Phaser.Actions.PlaceOnCircle( balls.getChildren(), circle);
return balls;
}
generateDance() {
this.spinSpeed = 0.003;
return this.tweens.addCounter({
from: 220,
to: 160,
duration: 9000,
delay: 2000,
ease: 'Sine.easeInOut',
repeat: -1,
yoyo: true
});
}
update() {
this.playerEyes.update();
Phaser.Actions.RotateAroundDistance( this.balls.getChildren(), { x: 400, y: 300 }, this.spinSpeed, this.dance.getValue());
}
我使用了 Phaser 3 示例中的代码
这是 https://phaser.io/examples/v3/view/tweens/tween-time-scale
现在两个按钮都可以正常工作了
generateDance() {
this.downButton = this.add.image(230, 530, 'up-bubble').setInteractive();
this.upButton = this.add.image( 80, 530, 'down-bubble').setInteractive();
this.spinSpeed = 0.003;
this.downButton.on ('pointerdown', (event) => {
if (this.spinSpeed < 1) { this.spinSpeed += 0.002; }
});
this.upButton.on('pointerdown', (event) => {
if (this.spinSpeed > 0 ) { this.spinSpeed -= 0.001; }
});
return this.tweens.addCounter({
from: 220,
to: 160,
duration: 9000,
delay: 2000,
ease: 'Sine.easeInOut',
repeat: -1,
yoyo: true
});
}
代码好像有问题,我加这段代码的时候一键减速一键加速,
this.downButton = this.add.image(80, 530, 'up-bubble').setInteractive();
this.upButton = this.add.image(230, 530, 'down-bubble').setInteractive();
this.input.on('gameobjectup', function (pointer, gameobject) {
if (gameobject === this.downButton && this.spinSpeed > 0)
{
this.spinSpeed -= 0.1;
}
else if (gameobject === this.upButton && this.spinSpeed < 9.9)
{
this.spinSpeed += 0.1;
}
});
但是,当我在 generateBalls() 之间添加这段代码时,它根本不起作用,它不起作用,
generateBalls() {
const hitArea = new Phaser.Geom.Rectangle(0, 0, 32, 32);
const hitAreaCallback = Phaser.Geom.Rectangle.Contains;
const circle = new Phaser.Geom.Circle(400, 300, 220);
const balls = this.add.group(null, {
key: 'balls',
frame: [0, 1, 5],
repeat: 5,
setScale: { x: 3, y: 3 },
hitArea: hitArea,
hitAreaCallback: hitAreaCallback,
});
this.downButton = this.add.image(80, 530, 'up-bubble').setInteractive();
this.upButton = this.add.image(230, 530, 'down-bubble').setInteractive();
this.input.on('gameobjectup', function (pointer, gameobject) {
if (gameobject === this.downButton && this.spinSpeed > 0)
{
this.spinSpeed -= 0.1;
}
else if (gameobject === this.upButton && this.spinSpeed < 9.9)
{
this.spinSpeed += 0.1;
}
});
Phaser.Actions.PlaceOnCircle( balls.getChildren(), circle);
return balls;
}
generateDance() {
this.spinSpeed = 0.003;
return this.tweens.addCounter({
from: 220,
to: 160,
duration: 9000,
delay: 2000,
ease: 'Sine.easeInOut',
repeat: -1,
yoyo: true
});
}
update() {
this.playerEyes.update();
Phaser.Actions.RotateAroundDistance( this.balls.getChildren(), { x: 400, y: 300 }, this.spinSpeed, this.dance.getValue());
}
我使用了 Phaser 3 示例中的代码 这是 https://phaser.io/examples/v3/view/tweens/tween-time-scale
现在两个按钮都可以正常工作了
generateDance() {
this.downButton = this.add.image(230, 530, 'up-bubble').setInteractive();
this.upButton = this.add.image( 80, 530, 'down-bubble').setInteractive();
this.spinSpeed = 0.003;
this.downButton.on ('pointerdown', (event) => {
if (this.spinSpeed < 1) { this.spinSpeed += 0.002; }
});
this.upButton.on('pointerdown', (event) => {
if (this.spinSpeed > 0 ) { this.spinSpeed -= 0.001; }
});
return this.tweens.addCounter({
from: 220,
to: 160,
duration: 9000,
delay: 2000,
ease: 'Sine.easeInOut',
repeat: -1,
yoyo: true
});
}