Methods
# async changeEffect(effect, n)
change an effect.
Parameters:
Name | Type | Description |
---|---|---|
effect |
"colour"
|
"fisheye"
|
"pixelate"
|
"whirl"
|
"mosaic"
|
"brightness"
|
"ghost"
|
Effect to change. |
n |
number
|
Value to change by.. |
Example
await sprite.looks.changeEffect("colour",42);
# async changeLayers(layer)
change layer by X
Parameters:
Name | Type | Description |
---|---|---|
layer |
number
|
Example
await this.renderLoop.changeLayers(1);
# async changeSize(inSize)
Change the sprite size
Parameters:
Name | Type | Description |
---|---|---|
inSize |
number
|
Size to change by. |
Promise. Await function to wait for the RenderLoop.
Example
await sprite.looks.changeSize(32);
# async changeX(x)
Change x position by n.
Parameters:
Name | Type | Description |
---|---|---|
x |
number
|
value to change by |
Promise. Await function to wait for the RenderLoop.
Example
await sprite.motion.changeX(5);
# async changeY(y)
Change y position by n.
Parameters:
Name | Type | Description |
---|---|---|
y |
number
|
value to change by |
Promise. Await function to wait for the RenderLoop.
Example
await sprite.motion.changeY(5);
# async clearEffects()
Set all effects to 0, thus restoring the sprite's appearance to the default.
Example
await sprite.looks.changeEffect("colour",42);
await sprite.looks.clearEffects();
# async colourTouchingColour(spriteColour, outerColour)
Check if one colour in a sprite is touching another colour anywhere.
Parameters:
Name | Type | Description |
---|---|---|
spriteColour |
Array
|
Colour in sprite to check. |
outerColour |
Array
|
Colour outside sprite to check. |
boolean
Example
console.log(await sprite.sensing.colourTouchingColour([255, 171, 25],[256,256,256]))
# async costumeNumber()
Get the current costume number.
current costume number.
Example
console.log(sprite.looks.costumeNumber());
# async distanceTo(object)
Distance from one object to another.
Parameters:
Name | Type | Description |
---|---|---|
object |
"mouse"
|
Sprite
|
Object to check. |
number
Example
console.log(await sprite.sensing.distanceTo("mouse"));
# getRendererProps()
Internal: returns an object describing the state of the sprite to be passed to the renderer
# async glide(x, y, secs)
Move to a position over n seconds.
Parameters:
Name | Type | Description |
---|---|---|
x |
number
|
x position |
y |
number
|
y position |
secs |
number
|
seconds |
Promise. Await function to wait for the RenderLoop.
Example
await sprite.motion.glide(200,100,3);
# async glideTo(target, secs)
Move to a target over n seconds. Accepts "random" or sprite.
Parameters:
Name | Type | Description |
---|---|---|
target |
"random"
|
"mouse"
|
Sprite
|
"random" or Sprite |
secs |
number
|
Promise. Await function to wait for the RenderLoop.
Example
await sprite.motion.glideTo("random",2);
# async goTo(target)
Go to object. "random","mouse" or a sprite.
Parameters:
Name | Type | Description |
---|---|---|
target |
"random"
|
"mouse"
|
Sprite
|
"random","mouse" or Sprite |
Promise. Await function to wait for the RenderLoop.
Example
await sprite.motion.goTo("random");
# async goToLayer(layer)
go to specific layer 0-INFINITY
Parameters:
Name | Type | Description |
---|---|---|
layer |
'back'
|
'front'
|
number
|
Example
await sprite.looks.goToLayer(100);
# async gotoXY(xPos, yPos)
Go to the given X and Y position.
Parameters:
Name | Type | Description |
---|---|---|
xPos |
number
|
x position |
yPos |
number
|
y position |
Promise. Await function to wait for the RenderLoop.
Example
await sprite.motion.goToXY(101,212);
# async moveSteps(steps)
Move in the current direction by n steps.
Parameters:
Name | Type | Description |
---|---|---|
steps |
number
|
steps to move |
Promise. Await function to wait for the RenderLoop.
Example
await sprite1.motion.moveSteps(10);
# async nextCostume()
Switches to the next costume
Promise. Await function to wait for the RenderLoop.
Example
await sprite.looks.nextCostume();
# async pointInDirection(dir)
Point to a direction.
Parameters:
Name | Type | Description |
---|---|---|
dir |
number
|
direction to turn to |
Promise. Await function to wait for the RenderLoop.
Example
await sprite.motion.pointInDirection(100);
# async pointTowards(target)
Point towards an object.
Parameters:
Name | Type | Description |
---|---|---|
target |
"random"
|
"mouse"
|
Sprite
|
"random","mouse" or Sprite |
Promise. Await function to wait for the RenderLoop.
Example
await sprite.motion.pointTowards("random");
# async setCostume(costume)
Set the sprite costume by id.
Parameters:
Name | Type | Description |
---|---|---|
costume |
number
|
costume id |
Promise. Await function to wait for the RenderLoop.
Example
console.log(sprite.costumes);
// [{"name":"him","data":"him.svg","type":"vector"},{"name":"them","data":"them.png","type":"bitmap"}]
await sprite.looks.setCostume(1);
// {"name":"them","data":"them.png","type":"bitmap"}
# async setEffect(effect, n)
set an effect.
Parameters:
Name | Type | Description |
---|---|---|
effect |
"colour"
|
"fisheye"
|
"pixelate"
|
"whirl"
|
"mosaic"
|
"brightness"
|
"ghost"
|
Effect to set. |
n |
number
|
New value. |
Example
await sprite.looks.setEffect("colour",42);
# async setScreenRefresh(value)
Enable or disable screen refresh for the sprite
Parameters:
Name | Type | Description |
---|---|---|
value |
boolean
|
# async setSize(inSize)
Set the sprite size
Parameters:
Name | Type | Description |
---|---|---|
inSize |
number
|
New size |
Promise. Await function to wait for the RenderLoop.
Example
await sprite.looks.setSize(32);
# async setX(x)
Set x position to n.
Parameters:
Name | Type | Description |
---|---|---|
x |
number
|
x position |
Promise. Await function to wait for the RenderLoop.
Example
await sprite.motion.setX(100);
# async setY(y)
Set y postition to n.
Parameters:
Name | Type | Description |
---|---|---|
y |
number
|
y position |
Promise. Await function to wait for the RenderLoop.
Example
await sprite.motion.setY(100);
# async size()
Get the current sprite scale.
current sprite size.
Example
console.log(sprite.looks.size());
# async touching(object)
Is a sprite touching another sprite
Parameters:
Name | Type | Description |
---|---|---|
object |
"mouse"
|
Sprite
|
object to check. |
boolean
Example
console.log(await sprite.sensing.touching("mouse"));
# async touchingColour(colourRGB)
Is a sprite touching a colour
Parameters:
Name | Type | Description |
---|---|---|
colourRGB |
Array
|
Colour to check |
boolean
Example
console.log(await sprite.sensing.touchingColour([256,256,256]));
# async turnLeft(deg)
Turn left by n degrees.
Parameters:
Name | Type | Description |
---|---|---|
deg |
number
|
degrees to turn by |
Promise. Await function to wait for the RenderLoop.
Example
await sprite.motion.turnLeft(10);
# async turnRight(deg)
Turn right by n degrees.
Parameters:
Name | Type | Description |
---|---|---|
deg |
number
|
degrees to turn by |
Promise. Await function to wait for the RenderLoop.
Example
await sprite.motion.turnRight(10);
# async waitForRenderLoop()
Internal: return a promise to pass to clients for wait for the render loop