在 Phaser 3 中如何让 Sprite 围绕一个点旋转?
How do I make a Sprite revolve around a point in Phaser 3?
在我的 Phaser 3 游戏中,我有一个对象,我想围绕一个特定半径(比如 5 个单位)的圆中的点 (x,y) 旋转。所有教程都在 Phaser 2 中,所以请帮助我。
我的猜测是将精灵的 anchor
设置在实际精灵之外。锚点是精灵上的轴心点或 "handle",有效地偏移 x、y 位置和角度等。设置锚点越远,半径越大。
然后添加一个补间来旋转角度。所以像:
// setAnchor, x offset = 10 to the right of the sprite, y offset = center of sprite
mysprite.setAnchor(10.0, 0.5);
var tween = game.tweens.add({
targets: mysprite,
angle: 360.0,
duration: 1500,
repeat: 0
});
您可以使用Phaser.Actions.RotateAroundDistance. There is an example here
万一link以后中断,参数为
RotateAroundDistance(point, x, y, angle, distance):
下面是一组对象的使用示例:
Phaser.Actions.RotateAroundDistance(group.getChildren(), { x: 400, y: 300 }, 0.02, 200)
在我的 Phaser 3 游戏中,我有一个对象,我想围绕一个特定半径(比如 5 个单位)的圆中的点 (x,y) 旋转。所有教程都在 Phaser 2 中,所以请帮助我。
我的猜测是将精灵的 anchor
设置在实际精灵之外。锚点是精灵上的轴心点或 "handle",有效地偏移 x、y 位置和角度等。设置锚点越远,半径越大。
然后添加一个补间来旋转角度。所以像:
// setAnchor, x offset = 10 to the right of the sprite, y offset = center of sprite
mysprite.setAnchor(10.0, 0.5);
var tween = game.tweens.add({
targets: mysprite,
angle: 360.0,
duration: 1500,
repeat: 0
});
您可以使用Phaser.Actions.RotateAroundDistance. There is an example here
万一link以后中断,参数为
RotateAroundDistance(point, x, y, angle, distance):
下面是一组对象的使用示例:
Phaser.Actions.RotateAroundDistance(group.getChildren(), { x: 400, y: 300 }, 0.02, 200)