javascript - 单击所需按钮 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
});
}
推荐阅读
- java - 如何在java中使用反射将对象传递给方法
- intellij-idea - 类似于 IntelliJ 如何以蓝色显示未提交的更改,是否有类似的方式来显示最后一次提交的更改?
- ios - Swift Combine 不会通过接收器更新值
- python - 如何监控多个进程并在一个退出时启动新的进程?
- c# - Excel 数据阅读器:变量列表使用 Clear() 方法丢失列表内容
- javascript - 如何获取对象内部的值?
- javascript - 奇怪的警告:已声明但它的值从未被读取
- javascript - Google App脚本根据该单元格的字体颜色清除单元格值
- xcode - Xcode 10.3 不适用于 MacOS Big Sur 11.0.1(非测试版)
- python - 爬取数据和调整数据时列表索引超出范围