Class: Sprite

Sprite(imgPaths)

Lightweight 2-D sprite with multiple costumes.

Constructor

new Sprite(imgPaths)

Parameters:
Name Type Description
imgPaths Array.<string> One or more costume URLs (loaded via p5.loadImage)
Source:

Methods

moveTo(x, y)

Teleport sprite instantly.
Parameters:
Name Type Description
x number New centre x (px)
y number New centre y (px)
Source:

setScale(s)

Uniformly scale sprite (affects draw size only).
Parameters:
Name Type Description
s number Scale factor (1 = natural)
Source:

setSize(w, h)

Set explicit draw size (bypasses Sprite#setScale).
Parameters:
Name Type Description
w number Width (px)
h number Height (px)
Source:

stepForward(pixels)

Step forward along current heading.
Parameters:
Name Type Description
pixels number Distance to move (px)
Source:

touched(other) → {boolean}

Simple circle-circle collision test.
Parameters:
Name Type Description
other Sprite Other sprite to test
Source:
Returns:
**true** if hit-circles overlap
Type
boolean