Class: Sprite

PodJS.ScratchPod. Sprite

Model for the Scratch Sprite class

Members

lastClickTime :number

The last time this Sprite was clicked, or 0 if never clicked, in millis since epoch.
Type:
  • number
Source:

Methods

_getCurrentCostumeObject() → {PodJS.ScratchPod.Costume}

Return the currently active costume object for this Sprite

This method is intended for internal use and may change in the future.

Source:
Returns:
Type
PodJS.ScratchPod.Costume

createListVariable(name)

Create a new list variable with the given name.
Parameters:
Name Type Description
name string the name of the list variable
Source:

createVariable(name)

Create a new variable with the given name.
Parameters:
Name Type Description
name string the name of the variable
Source:

getDirection()

Returns the current direction of the sprite, in degrees normalized to 0 (inclusive) to 360 (exclusive).
Source:

getListVariable(name)

Get the given list variable.
Parameters:
Name Type Description
name string the name of the list variable
Source:
Returns:
The list variable.

getVariable(name)

Get the value of the given variable.
Parameters:
Name Type Description
name string the name of the variable
Source:
Returns:
The value of the variable.

getVariableNames() → {string[]}

Returns the names of all the variables for this sprite.
Source:
Returns:
The names of all the variables
Type
string[]

go_xy(x, y)

Sets the sprite's X and Y position to the specified amounts.
Parameters:
Name Type Description
x number The x position, in pixels.
y number The y position, in pixels.
Source:

hasListVariable(name) → {boolean}

Returns true if the list variable exists for this sprite, or false if not.
Parameters:
Name Type Description
name string the name of the list variable
Source:
Returns:
true if the list variable exists or false if not.
Type
boolean

hasVariable(name) → {boolean}

Returns true if the variable exists for this sprite, or false if not.
Parameters:
Name Type Description
name string the name of the variable
Source:
Returns:
true if the variable exists or false if not.
Type
boolean

hide()

Shortcut for setShown(false)
Source:

isShown() → {boolean}

Returns whether this sprite is being shown or not.
Source:
Returns:
true if this is to be shown or false if not.
Type
boolean

loadCostume(name, src, scale)

Load and register a new costume for this sprite.
Parameters:
Name Type Description
name string the name of the costume
src string the href of where to find the image of the costume.
scale number (optional) - if specified, scale the image up or down by this amount, defaults to 1.0.
Source:

loadSound(name, src)

Load and register an audio file for this sprite.
Parameters:
Name Type Description
name string the name of the audio
src string the href of where to find the audio file.
Source:

moveSteps(steps)

Move this sprite the given number of steps.
Parameters:
Name Type Description
steps number The number of steps to move the Sprite, in the forward direction.
Source:

playSound(name)

Stop playing any sounds and play a new sound.
Parameters:
Name Type Description
name string the id of the sound to play
Source:

setCostume(name)

Change costume for this Sprite
Parameters:
Name Type Description
name string the name of the costume to change into, matching the name provided to loadCostume.
Source:

setDirection(degrees)

Point this sprite in the direction given
Parameters:
Name Type Description
degrees number The number of steps to move the Sprite, in the x direction.
Source:

setShown(show)

Changes whether this sprite is being shown or not.
Parameters:
Name Type Description
show boolean true if this is to be shown or false if not.
Source:

setVariable(name, value)

Set the value of the given variable to the given value.
Parameters:
Name Type Description
name string the name of the variable
value number | string the value to set the variable to
Source:

show()

Shortcut for setShown(true)
Source:

showListVariable(name, shown, x, y, width, height)

Sets whether this list variable is shown on the stage, and the location at which it is shown.
Parameters:
Name Type Description
name string the name of the list variable
shown boolean true if the list variable is to be shown, or false if not. Optional, defaults to true.
x number x position of the list variable on the stage (optional, defaults to 0)
y number y position of the list variable on the stage (optional, defaults to 0)
width number width Width of the box to show (optional, defaults to enough width to show small ints)
height number height of the box to show (optional, defaults to 8 rows worth of pixels)
Source:

showVariable(name, shown, x, y)

Sets whether this variable is shown on the stage, and the location at which it is shown.
Parameters:
Name Type Description
name string the name of the variable
shown boolean true if the variable is to be shown, or false if not. Optional, defaults to true.
x number x position of the variable on the stage (optional, defaults to 0)
y number y position of the variable on the stage (optional, defaults to 0)
Source:

stopAllSounds()

Stop playing any sounds for this sprite.
Source:

tick()

Gets called periodically by the environment when the next action is to take place.
Source:

translate(x, y)

Move this sprite the given number of steps in the X and Y directions.
Parameters:
Name Type Description
x number The number of steps to move the Sprite, in the x direction.
y number The number of steps to move the Sprite, in the y direction.
Source: