Skip to main content

RotateTo/RotateBy

Rotation actions are useful for creating spinning objects in your game.

RotateTo

This method will rotate an actor to the specified angle at the speed specified (in radians per second) and return back the actor. This method is part of the actor 'Action' fluent API allowing action chaining.

typescript
const actor = new ex.Actor({...});
// angle in radians and a speed in radians/second
actor.actions.rotateTo(Math.PI / 2, Math.PI, ex.RotationType.Clockwise);
typescript
const actor = new ex.Actor({...});
// angle in radians and a speed in radians/second
actor.actions.rotateTo(Math.PI / 2, Math.PI, ex.RotationType.Clockwise);

RotateBy

This method will rotate an actor by the specified angle offset, from it's current rotation given a certain speed in radians/sec and return back the actor. This method is part of the actor 'Action' fluent API allowing action chaining.

typescript
const actor = new ex.Actor({
...
rotation: Math.PI
});
// angle in radians and a speed in radians/second
// rotate relative to the actor's current angle
actor.actions.rotateBy(Math.PI / 2, Math.PI, ex.RotationType.CounterClockwise);
typescript
const actor = new ex.Actor({
...
rotation: Math.PI
});
// angle in radians and a speed in radians/second
// rotate relative to the actor's current angle
actor.actions.rotateBy(Math.PI / 2, Math.PI, ex.RotationType.CounterClockwise);

RotationType

Excalibur offers a choice in how an Actor rotates to a target angle.