Reputation: 311
In my Phaser 3 game I have an object which I want to revolve around a point (x,y) in a circle of a specific radius say 5 units. All the tutorials are in Phaser 2, so please help me out.
Upvotes: 0
Views: 3164
Reputation: 574
You can use Phaser.Actions.RotateAroundDistance. There is an example here
In case the link breaks in the future, the parameters are
RotateAroundDistance(point, x, y, angle, distance):
And an exmple use on a group of objects is below:
Phaser.Actions.RotateAroundDistance(group.getChildren(), { x: 400, y: 300 }, 0.02, 200)
Upvotes: 3
Reputation: 3058
My guess would be to set the anchor
of the sprite outside the actual sprite. The anchor is the pivot point or "handle" on the sprite, effectively an offset for the x,y position and angle etc. The further away you set the anchor, the bigger the radius will be.
And then add a tween to rotate the angle. So something like:
// 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
});
Upvotes: 1