Class: ScratchPod

PodJS. ScratchPod

pod.js pod that emulates the scratch programming language.

By default, when this pod initializes it looks for a div in the document with the id of "stage" (or whatever is specified in the options). It then attaches to that div and creates a resource called "stage" that is the Scratch stage.

new ScratchPod(options) → {PodJS.ScratchPod}

Parameters:
Name Type Description
options type The following parameters are supported:
  • scratch_stage_div - The id of the div to which the scratch stage should bind. Optional. If not specified, uses the div called "stage".
Source:
Returns:
Type
PodJS.ScratchPod

Classes

Sprite
ListVariable

Members

<inner> _audioFiles

Information about each audio resource. Key is spriteName::audioName or just ::audioName for the stage. Value is an AudioInfo object.
Source:

<inner> _resourcesPathPrefix

Path prefix to prepend to all resource paths.
Source:

Methods

_autoPositionListVariable(listVariable)

Automatically set the starting position of the list variable when shown.
Parameters:
Name Type Description
listVariable PodJS.ScratchPod.ListVariable The list variable to position.
Source:

_autoPositionVariable(variable)

Automatically set the starting position of the variable when shown.
Parameters:
Name Type Description
variable PodJS.ScratchPod.Variable The variable to position.
Source:

createListVariable(name)

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

createVariable(name)

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

getBlockTypes() → {object[]}

Part of the Pod standard interface - return information about the blocks provided by the scratch pod.
Source:
Returns:
One info object for each block.
Type
object[]

getListVariable(name) → {PodJS.ScratchPod.ListVariable}

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

getResourceTypes() → {object[]}

Part of the Pod standard interface - return information about the resources provided by the scratch pod.
Source:
Returns:
One info object for each resource.
Type
object[]

getStage() → {PodJS.ScratchPod.Stage}

Returns the stage.
Source:
Returns:
The stage
Type
PodJS.ScratchPod.Stage

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.

hasListVariable(name) → {boolean}

Returns true if the list variable exists for all sprites, 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 all sprites, 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

newBlock(blockType, resource, script) → {PodJS.Pod#Block}

Part of the Pod standard interface - called when a PodJS.ScriptBuilder wishes to create a new instance of a block.
Parameters:
Name Type Description
blockType string The type of block to be created (e.g. "gotoXY"). Must be one of the block types returned by PodJS.Pod#getBlockTypes.
resource PodJS.Block#Resource The resource this block is to be bound to.
script PodJS.Script The script this block is bound to.
Source:
Throws:
  • If the block type provided was not one of the valid block types returned by PodJS.Pod#getBlockTypes. This check is performed by PodJS.Pod#newBlockClass.
    Type
    Error
  • If the block to be returned would not be compatible with the resource provided. This check must be performed by the subclass.
    Type
    Error
Returns:
The instance of the block.
Type
PodJS.Pod#Block

newResource(resourceType, resourceName, options) → {PodJS.Pod#Resource}

Part of the Pod standard interface - called when the environment or an application wishes to create a new resource of the given type.
Parameters:
Name Type Argument Description
resourceType string The type of resource to be created (e.g. "sprite"). Must be one of the resource types returned by getResourceTypes.
resourceName string The name of the resource to create. This name must be unique for the type of resource so that the resource can be later retrieved and, if necessary, deleted.
options object <optional>
Set of parameters to be used when creating the resource.
Source:
Throws:
Returns:
Returns the instance of the resource.
Type
PodJS.Pod#Resource

newSprite(name) → {PodJS.ScratchPod.Sprite}

Convenience method to create a new sprite resource.
Parameters:
Name Type Description
name string The name of the sprite to create. This name must be unique for all sprites.
Source:
Throws:
If a resource of this type already exists with the given name. This checking is handled by PodJS.Pod#newResourceClass.
Type
Error
Returns:
Returns the instance of the Sprite.
Type
PodJS.ScratchPod.Sprite

resourcesPath(path)

Sets the directory that all resources are relative to.
Parameters:
Name Type Description
path string The path prefix for all resources loaded by this pod. If it does not end in '/', a '/' will be added.
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:

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:

sprite(name) → {PodJS.ScratchPod.Sprite}

Returns the sprite with the given name
Parameters:
Name Type Description
name string the name of the sprite
Source:
Returns:
the sprite
Type
PodJS.ScratchPod.Sprite

stopAllSounds()

Stop playing all sounds being played by scratch resources.
Source:

<inner> _htmlEscape()

Sanitize HTML Source: http://stackoverflow.com/questions/295566/sanitize-rewrite-html-on-the-client-side
Source: