Sprite

Sprite

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, SpriteAnimation, or name of a SpriteAnimation, 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.
Source:
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

Sprite

Members

allowSleeping :Boolean

This property disables 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.
Default Value:
  • true
Source:
Type:
  • Boolean

ani :SpriteAnimation

Reference to the sprite's current animation.
Source:
Type:

animation :SpriteAnimation

Reference to the sprite's current animation.
Source:
Type:

anis :SpriteAnimations

Keys are the animation label, values are SpriteAnimation objects
Source:
Type:

autoDraw :Boolean

autoDraw is a property of all groups that controls whether a group is automatically drawn to the screen after the end of each draw cycle. It only needs to be set to false once and then it will remain false for the rest of the sketch, unless changed.
Default Value:
  • true
Source:
Type:
  • Boolean

autoUpdate :Boolean

autoUpdate is a property of all groups that controls whether a group is automatically updated after the end of each draw cycle. It only needs to be set to false once and then it will remain false for the rest of the sketch, unless changed.
Default Value:
  • true
Source:
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.
Source:
Type:
  • Number
Example
sprite.bearing = angle;
sprite.applyForce(amount);

bounciness :Number

The bounciness of the sprite's physics body.
Default Value:
  • 0.2
Source:
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". 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.
Default Value:
  • 'dynamic'
Source:
Type:
  • String

color :p5.Color

The sprite's current color. By default sprites get a random color.
Default Value:
  • random color
Source:
Type:
  • p5.Color

colour :p5.Color

Alias for color. colour is the British English spelling.
Default Value:
  • random color
Source:
Type:
  • p5.Color

d :Number

The diameter of a circular sprite.
Source:
Type:
  • Number

debug :Boolean

If true, an outline of the sprite's collider will be drawn.
Default Value:
  • false
Source:
Type:
  • Boolean

density :Number

The density of the sprite's physics body.
Default Value:
  • 5
Source:
Type:
  • Number

diameter :Number

The diameter of a circular sprite.
Source:
Type:
  • Number

direction :Number

The angle of the sprite's movement or it's rotation angle if the sprite is not moving.
Default Value:
  • 0 ("right")
Source:
Type:
  • Number

drag :Number

The amount of resistance a sprite has to being moved.
Default Value:
  • 0
Source:
Type:
  • Number

draw :function

Displays the sprite. This function is called automatically at the end of each p5.js 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 p5.js 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.
Source:
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.
Default Value:
  • true
Source:
Type:
  • Boolean

fill :p5.Color

Alias for sprite.fillColor
Default Value:
  • random color
Source:
Type:
  • p5.Color

fillColor :p5.Color

Alias for sprite.color
Default Value:
  • random color
Source:
Type:
  • p5.Color

fixture

Returns the first node in a linked list of the planck physics body's fixtures.
Source:

fixtureList

Returns the first node in a linked list of the planck physics body's fixtures.
Source:

friction :Number

The amount the sprite's physics body resists moving when rubbing against another physics body.
Default Value:
  • 0.5
Source:
Type:
  • Number

h :Number

The height of the sprite.
Source:
Type:
  • Number

halfHeight :Number

Half the height of the sprite.
Source:
Type:
  • Number

halfWidth :Number

Half the width of the sprite.
Source:
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.
Default Value:
  • undefined
Source:
Type:
  • String

height :Number

The height of the sprite.
Source:
Type:
  • Number

hh :Number

Half the height of the sprite.
Source:
Type:
  • Number

hw :Number

Half the width of the sprite.
Source:
Type:
  • Number

image :p5.Image

A reference to the sprite's current image.
Source:
Type:
  • p5.Image

img :p5.Image

A reference to the sprite's current image.
Source:
Type:
  • p5.Image

isMoving :Boolean

Read only. True if the sprite is moving.
Source:
Type:
  • Boolean

isSuperFast :Boolean

Set this to true if the sprite goes really fast to prevent inaccurate physics simulation.
Default Value:
  • false
Source:
Type:
  • Boolean

kinematic :Boolean

True if the sprite's physics body is kinematic.
Default Value:
  • false
Source:
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.
Source:
Type:
  • Number

life :Number

When the physics simulation is progressed in `world.step`, 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!
Default Value:
  • 2147483647
Source:
Type:
  • Number

mass :Number

The mass of the sprite's physics body.
Source:
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
Default Value:
  • {x: false, y: false}
Source:
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
Default Value:
  • {x: 0, y: 0}
Source:
Type:
  • object

opacity :Number

The sprite's opacity. 0 is transparent, 1 is opaque.
Default Value:
  • 1
Source:
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.
Default Value:
  • false
Source:
Type:
  • Boolean

pos :p5.Vector

The position vector {x, y}
Source:
Type:
  • p5.Vector

position :p5.Vector

The position vector {x, y}
Source:
Type:
  • p5.Vector

previousPosition :Object

Verbose alias for sprite.prevPos
Source:
Type:
  • Object

previousRotation :Number

Verbose alias for sprite.prevRotation
Source:
Type:
  • Number

r :Number

The radius of a circular sprite.
Source:
Type:
  • Number

radius :Number

The radius of a circular sprite.
Source:
Type:
  • Number

removed :Boolean

If the sprite has been removed from the world.
Default Value:
  • false
Source:
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.
Default Value:
  • 0
Source:
Type:
  • Number

rotationDrag :Number

The amount the sprite resists rotating.
Default Value:
  • 0
Source:
Type:
  • Number

rotationLock :Boolean

If true, the sprite can not rotate.
Default Value:
  • false
Source:
Type:
  • Boolean

rotationSpeed :Number

The speed of the sprite's rotation in angles per frame.
Default Value:
  • 0
Source:
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.
Default Value:
  • 1
Source:
Type:
  • Number | Object

shape :String

The kind of shape: 'box', 'circle', 'chain', or 'polygon'.
Default Value:
  • box
Source:
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.
Default Value:
  • true
Source:
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.
Default Value:
  • 0
Source:
Type:
  • Number

static :Boolean

Is the sprite's physics collider static?
Default Value:
  • false
Source:
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.
Default Value:
  • undefined
Source:
Type:
  • p5.Color

strokeColor :p5.Color

Alias for sprite.stroke
Default Value:
  • undefined
Source:
Type:
  • p5.Color

strokeWeight :Number

The sprite's stroke weight, the thickness of its outline.
Default Value:
  • undefined
Source:
Type:
  • Number

textColor :p5.Color

The sprite's text fill color. Black by default.
Default Value:
  • black (#000000)
Source:
Type:
  • p5.Color

textFill :p5.Color

The sprite's text fill color. Black by default.
Default Value:
  • black (#000000)
Source:
Type:
  • p5.Color

textSize :Number

The sprite's text size, the sketch's current textSize by default.
Source:
Type:
  • Number

textStroke :p5.Color

The sprite's text stroke color. No stroke by default, does not inherit from the sketch's stroke color.
Default Value:
  • undefined
Source:
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.
Default Value:
  • undefined
Source:
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.
Default Value:
  • undefined
Source:
Type:
  • p5.Color

tintColor :p5.Color

Alias for sprite.tint
Default Value:
  • undefined
Source:
Type:
  • p5.Color

update :function

You can set the sprite's update function to a custom update function which by default, will be run after every p5.js draw call. This function updates the sprite's animation, mouse, and There's no way to individually update a sprite or group of sprites in the physics simulation though.
Source:
Type:
  • function

vel :p5.Vector

The sprite's velocity vector {x, y}
Default Value:
  • {x: 0, y: 0}
Source:
Type:
  • p5.Vector

velocity :p5.Vector

The sprite's velocity vector {x, y}
Default Value:
  • {x: 0, y: 0}
Source:
Type:
  • p5.Vector

vertices :Array

The sprite's vertices, in vertex mode format.
Source:
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.
Default Value:
  • true
Source:
Type:
  • Boolean

w :Number

The width of the sprite.
Source:
Type:
  • Number

width :Number

The width of the sprite.
Source:
Type:
  • Number

x :Number

The horizontal position of the sprite.
Source:
Type:
  • Number

y :Number

The vertical position of the sprite.
Source:
Type:
  • Number

Methods

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.
Source:
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.
Source:

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.
Source:
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`.
Source:
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`.
Source:
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.
Source:
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.
Source:
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.
Source:
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!
Source:
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.
Source:
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`.
Source:
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.
Source:
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.
Source:
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.
Source:
Parameters:
Name Type Attributes Description
target Sprite | Group
callback function <optional>
Returns:
Type:
Number
frames

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.
Source:
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.
Source:
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.
Source:
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.
Source:
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.
Source:
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.
Source:
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.
Source:
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.
Source:

removeColliders()

Removes the physics body colliders from the sprite but not overlap sensors.
Source:

removeSensors()

Removes overlap sensors from the sprite.
Source:

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.
Source:

resetMass()

Recalculates the sprite's mass based on its current density and size.
Source:

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.
Source:
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.
Source:
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.
Source:
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.
Source:
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`.
Source:
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

toString()

Warning: This function might be changed in a future release. Returns the sprite's unique identifier `sprite.idNum`.
Source:
Returns:
the sprite's id