new Sprite(xopt, yopt, wopt, hopt, collideropt)
Look at the Sprite reference pages before reading these docs.
The Sprite constructor can be used in many different ways.
In fact it's so flexible that I've only listed out some of the
most common ways it can be used in the examples section below.
Try experimenting with it! It's likely to work the way you
expect it to, if not you'll just get an error.
Special feature! If the first parameter to this constructor is a
loaded p5.Image, Ani, or name of a animation,
then the Sprite will be created with that animation. If the
dimensions of the sprite are not given, then the Sprite will be
created using the dimensions of the animation.
Every sprite you create is added to the `allSprites`
group and put on the top draw order layer, in front of all
previously created sprites.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
x |
Number
|
<optional> |
horizontal position of the sprite |
y |
Number
|
<optional> |
vertical position of the sprite |
w |
Number
|
<optional> |
width of the placeholder rectangle and of the collider until an image or new collider are set. *OR* If height is not set then this parameter becomes the diameter of the placeholder circle. |
h |
Number
|
<optional> |
height of the placeholder rectangle and of the collider until an image or new collider are set |
collider |
String
|
<optional> |
collider type is 'dynamic' by default, can be 'static', 'kinematic', or 'none' |
Example
let spr = new Sprite();
let rectangle = new Sprite(x, y, width, height);
let circle = new Sprite(x, y, diameter);
let spr = new Sprite(aniName, x, y);
let line = new Sprite(x, y, [length, angle]);
Classes
Members
allowSleeping :Boolean
Controls the ability for a sprite to "sleep".
"Sleeping" sprites are not included in the physics simulation, a
sprite starts "sleeping" when it stops moving and doesn't collide
with anything that it wasn't already touching.
Type:
-
Boolean
autoDraw :Boolean
Controls whether a sprite is drawn after each physics update,
when users let p5play automatically manage the frame cycle.
Type:
-
Boolean
autoUpdate :Boolean
Controls whether a sprite is updated before each physics update,
when users let p5play automatically manage the frame cycle.
Type:
-
Boolean
bearing :Number
A bearing indicates the direction that needs to be followed to
reach a destination. Setting a sprite's bearing doesn't do
anything by itself. You can apply a force at the sprite's
bearing angle using the `applyForce` function.
Type:
-
Number
Example
sprite.bearing = angle;
sprite.applyForce(amount);
bounciness :Number
The bounciness of the sprite's physics body.
Type:
-
Number
collider :String
The sprite's collider type. Default is "dynamic".
The collider type can be one of the following strings:
"dynamic", "static", "kinematic", "none".
The letters "d", "s", "k", "n" can be used as shorthand.
When a sprite with a collider type of "d", "s", or "k" is
changed to "none", or vice versa, the sprite will
maintain its current position, velocity, rotation, and
rotation speed.
Sprites can't have their collider type
set to "none" if they have a polygon or chain collider,
multiple colliders, or multiple sensors.
To achieve the same effect as setting collider type
to "none", use `.overlaps(allSprites)` to have your
sprite overlap with all sprites.
Type:
-
String
color :p5.Color
The sprite's current color. By default sprites get a random color.
Type:
-
p5.Color
colour :p5.Color
Alias for color. colour is the British English spelling.
Type:
-
p5.Color
debug :Boolean
If true, an outline of the sprite's collider will be drawn.
Type:
-
Boolean
density :Number
The density of the sprite's physics body.
Type:
-
Number
direction :Number
The angle of the sprite's movement.
Type:
-
Number
drag :Number
The amount of resistance a sprite has to being moved.
Type:
-
Number
draw :function
Displays the sprite.
This function is called automatically at the end of each
sketch `draw` function call but it can also be run
by users to customize the order sprites are drawn in relation
to other stuff drawn to the canvas. Also see the sprite.layer
property.
A sprite's draw function can be overridden with a
custom draw function, inside this function (0, 0) is the center of
the sprite.
Using this function actually calls the sprite's internal `_display`
function, which sets up the canvas for drawing the sprite before
calling the sprite's `_draw` function. See the example below for how to
run the sprite's default `_draw` function inside your custom `draw` function.
Type:
-
function
Example
let defaultDraw = sprite._draw;
sprite.draw = function() {
// add custom code here
defaultDraw();
}
dynamic :Boolean
True if the sprite's physics body is dynamic.
Type:
-
Boolean
fill :p5.Color
Alias for sprite.fillColor
Type:
-
p5.Color
fixture
Returns the first node in a linked list of the planck physics
body's fixtures.
fixtureList
Returns the first node in a linked list of the planck physics
body's fixtures.
friction :Number
The amount the sprite's physics body resists moving
when rubbing against another physics body.
Type:
-
Number
gravityScale :Number
A ratio that defines how much the sprite is affected by gravity.
Type:
-
Number
heading :String
The sprite's heading. This is a string that can be set to
"up", "down", "left", "right", "upRight", "upLeft", "downRight"
It ignores cardinal direction word order, capitalization, spaces,
underscores, and dashes.
Type:
-
String
image :p5.Image
The sprite's image or current frame of animation.
When `sprite.image` is set, two properties are added:
`sprite.image.offset` determines the x and y position the image
should be drawn at relative to the sprite's center.
`sprite.image.scale` determines the x and y scale of the image.
Type:
-
p5.Image
isMoving :Boolean
Read only. True if the sprite is moving.
Type:
-
Boolean
isSuperFast :Boolean
Set this to true if the sprite goes really fast to prevent
inaccurate physics simulation.
Type:
-
Boolean
kinematic :Boolean
True if the sprite's physics body is kinematic.
Type:
-
Boolean
layer :Number
By default sprites are drawn in the order they were created in.
You can change the draw order by editing sprite's layer
property. Sprites with the highest layer value get drawn first.
Type:
-
Number
life :Number
When the physics simulation is progressed in `world.physicsUpdate`,
each sprite's life is decreased by `world.timeScale`.
If life becomes less than or equal to 0, the sprite will
be removed.
It must be set to a positive integer lower than the max value of
a 32 bit signed integer, 2147483647, which is the default value
representing infinite life. This limitation makes sprite netcode
smaller. But don't worry, at 60 fps this gives users a definable
sprite life range between 1 frame and ~411 days!
Type:
-
Number
mirror :Object
The sprite's mirror states.
Properties:
Name | Type | Description |
---|---|---|
x |
Boolean
|
the sprite's horizontal mirror state |
y |
Boolean
|
the sprite's vertical mirror state |
Type:
-
Object
offset :object
Offsetting the sprite moves the sprite's physics body relative
to its center.
The sprite's x and y properties represent its center in world
coordinates. This point is also the sprite's center of rotation.
Properties:
Name | Type | Description |
---|---|---|
x |
Number
|
the sprite's horizontal offset |
y |
Number
|
the sprite's vertical offset |
Type:
-
object
opacity :Number
The sprite's opacity. 0 is transparent, 1 is opaque.
Type:
-
Number
pixelPerfect :Boolean
By default p5play draws sprites with subpixel rendering.
Set pixelPerfect to true to make p5play always display sprites
at integer pixel precision. This is useful for making retro games.
Type:
-
Boolean
postDraw :function
Runs at the end of the p5play frame cycle.
Users should not directly run this function.
Type:
-
function
removed :Boolean
If the sprite has been removed from the world.
Type:
-
Boolean
rotation :Number
The angle of the sprite's rotation, not the direction it's moving.
If angleMode is set to "degrees", the value will be returned in
a range of -180 to 180.
Type:
-
Number
rotationDrag :Number
The amount the sprite resists rotating.
Type:
-
Number
rotationLock :Boolean
If true, the sprite can not rotate.
Type:
-
Boolean
rotationSpeed :Number
The speed of the sprite's rotation in angles per frame.
Type:
-
Number
scale :Number|Object
Scale of the sprite's physics body. Default is {x: 1, y: 1}
The getter for sprite.scale returns the scale as an object with
x and y properties.
The valueOf function for sprite.scale returns the scale as a
number. This enables users to do things like `sprite.scale *= 2`
to double the sprite's scale.
Type:
-
Number
|Object
shape :String
The kind of shape: 'box', 'circle', 'chain', or 'polygon'.
If a sprite with a circle shape has its shape type changed to
chain or polygon, the circle will be turned into a dodecagon.
Type:
-
String
sleeping :Boolean
Wake a sprite up or put it to sleep.
"Sleeping" sprites are not included in the physics simulation, a
sprite starts "sleeping" when it stops moving and doesn't collide
with anything that it wasn't already touching.
Type:
-
Boolean
speed :Number
The sprite's speed.
Setting speed to a negative value will make the sprite move
180 degrees opposite of its current direction angle.
Type:
-
Number
static :Boolean
Is the sprite's physics collider static?
Type:
-
Boolean
stroke :p5.Color
Overrides sprite's stroke color. By default the stroke of a sprite
is determined by its collider type, which can also be overridden
by the sketch's stroke color.
Type:
-
p5.Color
strokeWeight :Number
The sprite's stroke weight, the thickness of its outline.
Type:
-
Number
textColor :p5.Color
The sprite's text fill color. Black by default.
Type:
-
p5.Color
textFill :p5.Color
The sprite's text fill color. Black by default.
Type:
-
p5.Color
textSize :Number
The sprite's text size, the sketch's current textSize by default.
Type:
-
Number
textStroke :p5.Color
The sprite's text stroke color.
No stroke by default, does not inherit from the sketch's stroke color.
Type:
-
p5.Color
textStrokeWeight :Number
The sprite's text stroke weight, the thickness of its outline.
No stroke by default, does not inherit from the sketch's stroke weight.
Type:
-
Number
tile :String
The tile string represents the sprite in a tile map.
Type:
-
String
tileSize :Number
The tile size is used to change the size of one unit of
measurement for the sprite.
For example, if the tile size is 16, then a sprite with
x=1 and y=1 will be drawn at position (16, 16) on the canvas.
Type:
-
Number
tint :p5.Color
Tint color applied to the sprite when drawn.
Note that this is not good for performance, you should probably
pre-render the effect if you want to use it a lot.
Type:
-
p5.Color
tintColor :p5.Color
Alias for sprite.tint
Type:
-
p5.Color
update :function
Runs before each physics update by default, when p5play is automatically
managing the frame cycle.
Set this to a custom function that handles input, directs sprite movement,
and performs other tasks that should run before the physics update.
Optionally, users can run this function manually in p5play's `update`
function.
Type:
-
function
vel :p5.Vector
The sprite's velocity vector {x, y}
Type:
-
p5.Vector
velocity :p5.Vector
The sprite's velocity vector {x, y}
Type:
-
p5.Vector
vertices :Array
The sprite's vertices, in vertex mode format.
Type:
-
Array
visible :Boolean
If true the sprite is shown, if set to false the sprite is hidden.
Becomes null when the sprite is off screen but will be drawn and
set to true again if it goes back on screen.
Type:
-
Boolean
Methods
addAni(name, animation)
Adds an animation to the sprite. Use this function in the `preload`
function. You don't need to name the animation if the sprite will only
use one animation. See Ani for more information.
If an animation was already added to a different sprite or group,
it can not be added to another sprite or group. A clone (copy) of
the animation will be automatically created and added instead.
Parameters:
Name | Type | Description |
---|---|---|
name |
String
|
Ani identifier |
animation |
Ani
|
The preloaded animation |
Example
sprite.addAni(name, animation);
sprite.addAni(name, frame1, frame2, frame3...);
sprite.addAni(name, atlas);
addAnis(atlases)
Add multiple animations to the sprite.
Parameters:
Name | Type | Description |
---|---|---|
atlases |
Object
|
an object with animation names as keys and an animation or animation atlas as values |
Example
sprite.addAnis({
name0: atlas0,
name1: atlas1
});
addCollider(offsetX, offsetY, w, h)
Adds a collider (fixture) to the sprite's physics body.
It accepts parameters in a similar format to the Sprite
constructor except the first two parameters are x and y offsets,
the distance new collider should be from the center of the sprite.
This function also recalculates the sprite's mass based on the
size of the new collider added to it. However, it does not move
the sprite's center of mass, which makes adding multiple colliders
to a sprite easier.
For better physics simulation results, run the `resetCenterOfMass`
function after you finish adding colliders to a sprite.
One limitation of the current implementation is that sprites
with multiple colliders can't have their collider
type changed without losing every collider added to the
sprite besides the first.
Parameters:
Name | Type | Description |
---|---|---|
offsetX |
Number
|
distance from the center of the sprite |
offsetY |
Number
|
distance from the center of the sprite |
w |
Number
|
width of the collider |
h |
Number
|
height of the collider |
addDefaultSensors()
This function is used internally if a sprite overlap detection
function is called but the sprite has no overlap sensors.
It creates sensor fixtures that are the same size as the sprite's
colliders. If you'd like to add more sensors to a sprite, use the
addSensor function.
addSensor(offsetX, offsetY, w, h)
Adds a sensor to the sprite's physics body.
Sensors can't displace or be displaced by colliders.
Sensors don't have any mass or other physical properties.
Sensors simply detect overlaps with other sensors.
This function accepts parameters in a similar format to the Sprite
constructor except the first two parameters are x and y offsets,
the relative distance the new sensor should be from the center of
the sprite.
If a sensor is added to a sprite that has no collider (type "none")
then internally it will be given a dynamic physics body that isn't
affected by gravity so that the sensor can be added to it.
Parameters:
Name | Type | Description |
---|---|---|
offsetX |
Number
|
distance from the center of the sprite |
offsetY |
Number
|
distance from the center of the sprite |
w |
Number
|
width of the collider |
h |
Number
|
height of the collider |
angleTo(x, y) → {Number}
Finds the angle from this sprite to the given position or object
with x and y properties.
Can be used to change the direction of a sprite so it moves
to a position or object, as shown in the example.
Used internally by `moveTo` and `moveTowards`.
Parameters:
Name | Type | Description |
---|---|---|
x |
Number
|
|
y |
Number
|
Returns:
- Type:
-
Number
angle
Example
spriteA.direction = spriteA.angleTo(spriteB);
angleToFace(x, y, facing) → {Number}
Finds the minimum angle distance that the sprite would have
to rotate to "face" a position at a specified facing rotation,
taking into account the current rotation of the sprite.
Used internally by `rotateMinTo` and `rotateTowards`.
Parameters:
Name | Type | Description |
---|---|---|
x |
Number
|
|
y |
Number
|
|
facing |
Number
|
relative angle the sprite should be at when "facing" the position, default is 0 |
Returns:
- Type:
-
Number
the minimum angle distance to face the position
applyForce(amount, originopt)
If this function is given a force amount, the force is applied
at the angle of the sprite's current bearing. Force can
also be given as a vector.
The origin of the force can be given as a vector or as x and y
coordinates. If no origin is given, the force is applied to the
center of the sprite.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
amount |
Number
|
||
origin |
Vector
|
<optional> |
Example
sprite.applyForce(amount);
sprite.applyForce(amount, {x: originX, y: originY});
sprite.applyForce(x, y);
sprite.applyForce(x, y, {x: originX, y: originY});
sprite.applyForce({x, y}, {x: originX, y: originY});
applyForceScaled(amount, originopt)
Applies a force that's scaled to the sprite's mass.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
amount |
Number
|
||
origin |
Vector
|
<optional> |
applyTorque(torque)
Apply a torque on the sprite's physics body.
Torque is the force that causes rotation.
A positive torque will rotate the sprite clockwise.
A negative torque will rotate the sprite counter-clockwise.
This function is the rotational equivalent of applyForce().
It will not imperatively set the sprite's rotation.
Parameters:
Name | Type | Description |
---|---|---|
torque |
Number
|
The amount of torque to apply. |
attractTo(x, y, force, radiusopt, easingopt)
Applies a force to the sprite's center of mass attracting it to
the given position.
Radius and easing not implemented yet!
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
x |
Number
|
||
y |
Number
|
||
force |
Number
|
||
radius |
Number
|
<optional> |
infinite if not given |
easing |
Number
|
<optional> |
solid if not given |
Example
sprite.attractTo(x, y, force);
sprite.attractTo({x, y}, force);
(async) changeAni(…anis)
Changes the sprite's animation. Use `addAni` to define the
animation(s) first.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
anis |
String
|
<repeatable> |
the names of one or many animations to be played in sequence |
Returns:
A promise that fulfills when the animation or sequence of animations
completes
changeAnimation(…anis)
Changes the sprite's animation. Use `addAni` to define the
animation(s) first. Alt for `changeAni`.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
anis |
String
|
<repeatable> |
the names of one or many animations to be played in sequence |
Returns:
A promise that fulfills when the animation or sequence of animations
completes
collided(target, callbackopt) → {Boolean}
Returns true on the first frame that the sprite no longer overlaps
with the target sprite or group.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
target |
Sprite
|
Group
|
||
callback |
function
|
<optional> |
Returns:
- Type:
-
Boolean
collides(target, callbackopt)
Returns true on the first frame that the sprite collides with the
target sprite or group.
Custom collision event handling can be done by using this function
in an if statement or adding a callback as the second parameter.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
target |
Sprite
|
Group
|
||
callback |
function
|
<optional> |
colliding(target, callbackopt) → {Number}
Returns a truthy value while the sprite is colliding with the
target sprite or group. The value is the number of frames that
the sprite has been colliding with the target.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
target |
Sprite
|
Group
|
||
callback |
function
|
<optional> |
Returns:
- Type:
-
Number
frames
distanceTo(o) → {Number}
Returns the distance to another sprite, the mouse, a touch,
or any other object with x and y properties. Uses p5's `dist`
function.
Parameters:
Name | Type | Description |
---|---|---|
o |
Sprite
|
object with x and y properties |
Returns:
- Type:
-
Number
distance
move(distance, directionopt, speedopt) → {Promise}
Move the sprite a distance from its current position.
You can specify the `direction` and `speed` of movement as
parameters or set these properties before using this function.
When `tileSize` is not 1, distance is divisible by 0.5,
and a direction name or cardinal direction angle is given,
the distance the sprite moves will be rounded up to the
nearest half tile.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
distance |
Number
|
||
direction |
Number
|
String
|
<optional> |
direction angle in degrees or a cardinal direction name, if not given the sprite's current direction is used |
speed |
Number
|
<optional> |
if not given, the sprite's current `speed` is used, unless it's 0 then it's given a default speed of 1 or 0.1 if the sprite's tileSize is greater than 1 |
Returns:
- Type:
-
Promise
resolves when the movement is complete or cancelled
Example
sprite.direction = -90;
sprite.speed = 2;
sprite.move(1);
// or
sprite.move(1, -90, 2);
// or
sprite.move('up', 2);
moveAway(x, y, repelopt)
Moves the sprite away from a position, the opposite of moveTowards,
at a percentage of the distance between itself and the position.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
x |
Number
|
Object
|
destination x or an object with x and y properties | |
y |
Number
|
destination y | |
repel |
Number
|
<optional> |
percent of the distance to the repel position as a 0-1 value, default is 0.1 (10% repel) |
moveTo(x, y, speedopt) → {Promise}
Move the sprite to a position.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
x |
Number
|
Object
|
destination x or an object with x and y properties | |
y |
Number
|
destination y | |
speed |
Number
|
<optional> |
if not given, the sprite's current speed is used, unless it is 0 then it is given a default speed of 1 or 0.1 if the sprite's tileSize is greater than 1 |
Returns:
- Type:
-
Promise
resolves to true when the movement is complete
or to false if the sprite will not reach its destination
moveTowards(x, y, trackingopt)
Moves a sprite towards a position at a percentage of the distance
between itself and the destination.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
x |
Number
|
Object
|
destination x or an object with x and y properties | |
y |
Number
|
destination y | |
tracking |
Number
|
<optional> |
percent of the distance to move towards the destination as a 0-1 value, default is 0.1 (10% tracking) |
overlapped(target, callbackopt) → {Boolean}
Returns true on the first frame that the sprite no longer overlaps
with the target sprite or group.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
target |
Sprite
|
Group
|
||
callback |
function
|
<optional> |
Returns:
- Type:
-
Boolean
overlapping(target, callbackopt) → {Number}
Returns a truthy value while the sprite is overlapping with the
target sprite or group. The value returned is the number of
frames the sprite has been overlapping with the target.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
target |
Sprite
|
Group
|
||
callback |
function
|
<optional> |
Returns:
- Type:
-
Number
frames
overlaps(target, callbackopt)
Returns true on the first frame that the sprite overlaps with the
target sprite or group.
Custom overlap event handling can be done by using this function
in an if statement or adding a callback as the second parameter.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
target |
Sprite
|
Group
|
||
callback |
function
|
<optional> |
remove()
Removes the Sprite from the sketch and all the groups it
belongs to.
When a sprite is removed it will not be drawn or updated anymore.
If it has a physics body, it will be removed from the
physics world simulation.
There's no way to undo this operation. If you want to hide a
sprite use `sprite.visible = false` instead.
removeColliders()
Removes the physics body colliders from the sprite but not
overlap sensors.
resetCenterOfMass()
Recalculates the sprite's center of mass based on the masses of
its fixtures and their positions. Moves the sprite's center to
the new center of mass, but doesn't actually change the positions
of its fixtures relative to the world.
In p5play a sprite's center (position) is always the same as its
center of mass and center of rotation.
resetMass()
Recalculates the sprite's mass based on its current
density and size.
Does not change the sprite's center of mass, to do so
use the `resetCenterOfMass` function.
rotate(angle, speedopt) → {Promise}
Rotates the sprite by an angle amount at a given rotation speed.
To achieve a clockwise rotation, use a positive angle and speed.
To achieve a counter-clockwise rotation, use a negative angle
or speed.
When the rotation is complete, the sprite's rotation speed is
set to 0 and sprite's rotation is set to the exact destination angle.
If the angle amount is not evenly divisible by the rotation speed,
the sprite's rotation speed will be decreased as it approaches the
destination angle.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
angle |
Number
|
the amount to rotate the sprite | |
speed |
Number
|
<optional> |
the absolute amount of rotation per frame, if not given the sprite's current `rotationSpeed` is used, if 0 it defaults to 1 |
Returns:
- Type:
-
Promise
a promise that resolves when the rotation is complete
rotateMinTo(angle, speed, facing)
Rotates the sprite by the smallest angular distance
to an angle or to face a position at a given absolute
rotation speed.
Parameters:
Name | Type | Description |
---|---|---|
angle |
Number
|
Object
|
angle or a position object with x and y properties |
speed |
Number
|
absolute amount of rotation per frame, if not given the sprite's current `rotationSpeed` is used |
facing |
Number
|
relative angle the sprite should be at when "facing" the given position, default is 0 |
rotateTo(angle, speedopt, facingopt) → {Promise}
Rotates the sprite to an angle or to face a position
at a given rotation speed.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
angle |
Number
|
Object
|
angle or a position object with x and y properties | |
speed |
Number
|
<optional> |
amount of rotation per frame, if not given the sprite's current `rotationSpeed` is used, if 0 it defaults to 1 |
facing |
Number
|
<optional> |
relative angle the sprite should be at when "facing" the given position, default is 0 |
Returns:
- Type:
-
Promise
a promise that resolves when the rotation is complete
Example
sprite.rotationSpeed = 2;
sprite.rotateTo(180);
// or
sprite.rotateTo(180, 2);
// or
// (x, y, speed)
sprite.rotateTo(0, 100, 2);
// or
sprite.rotateTo({x: 0, y: 100}, 2);
rotateTowards(angle, trackingopt, facingopt)
Rotates the sprite towards an angle or position
with x and y properties.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
angle |
Number
|
Object
|
angle in degrees or an object with x and y properties | |
tracking |
Number
|
<optional> |
percent of the distance to rotate on each frame towards the target angle, default is 0.1 (10%) |
facing |
Number
|
<optional> |
(only specify if position is given) rotation angle the sprite should be at when "facing" the position, default is 0 |
rotationToFace(x, y, facingopt) → {Number}
Finds the rotation angle the sprite should be at when "facing"
a position.
Used internally by `rotateTo`.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
x |
Number
|
||
y |
Number
|
||
facing |
Number
|
<optional> |
relative angle the sprite should be at when "facing" the position, default is 0 |
Returns:
- Type:
-
Number
the rotation angle the sprite should be at when "facing" the position