RenderedTarget

RenderedTarget

Rendered target: instance of a sprite (clone), or the stage.

Constructor

new RenderedTarget(spritenon-null, runtime)

Parameters:
Name Type Description
sprite Sprite

Reference to the parent sprite.

runtime Runtime

Reference to the runtime.

Members

(static) EVENT_TARGET_MOVED :string

Event which fires when a target moves.

Type:
  • string

(static) EVENT_TARGET_VISUAL_CHANGE :string

Event which fires when a target changes visually, for updating say bubbles.

Type:
  • string

(static) ROTATION_STYLE_ALL_AROUND :string

Rotation style for "all around"/spinning.

Type:
  • string

(static) ROTATION_STYLE_LEFT_RIGHT :string

Rotation style for "left-right"/flipping.

Type:
  • string

(static) ROTATION_STYLE_NONE :string

Rotation style for "no rotation."

Type:
  • string

(static) VIDEO_STATE :string

Available states for video input.

Type:
  • string

currentCostume :number

Currently selected costume index.

Type:
  • number

direction :number

Scratch direction. Currently should range from -179 to 180.

Type:
  • number

draggable :boolean

Whether the rendered target is draggable on the stage

Type:
  • boolean

dragging :boolean

Drag state of this rendered target. If true, x/y position can't be changed by blocks.

Type:
  • boolean

(nullable) drawableID :Number

ID of the drawable for this rendered target, returned by the renderer, if rendered.

Type:
  • Number

(non-null) effects :Object.<string, number>

Map of current graphic effect values.

Type:
  • Object.<string, number>

isOriginal :boolean

Whether this represents an "original" non-clone rendered-target for a sprite, i.e., created by the editor and not clone blocks.

Type:
  • boolean

isStage :boolean

Whether this rendered target represents the Scratch stage.

Type:
  • boolean

(nullable) renderer :RenderWebGL

Reference to the global renderer for this VM, if one exists.

Type:
  • RenderWebGL

(non-null) rotationStyle :string

Current rotation style.

Type:
  • string

size :number

Size of rendered target as a percent of costume size.

Type:
  • number

(non-null) sprite :Sprite

Reference to the sprite that this is a render of.

Type:

tempo :number

Current tempo (used by the music extension). This property is global to the project and stored in the stage.

Type:
  • number

textToSpeechLanguage :string

The language to use for speech synthesis, in the text2speech extension. It is initialized to null so that on extension load, we can check for this and try setting it using the editor locale.

Type:
  • string

videoState :string

The state of the video input (used by extensions with camera input). This property is global to the project and stored in the stage.

Defaults to ON. This setting does not turn the video by itself. A video extension once loaded will set the video device to this setting. Set to ON when a video extension is added in the editor the video will start ON. If the extension is loaded as part of loading a saved project the extension will see the value set when the stage was loaded from the saved values including the video state.

Type:
  • string

videoTransparency :number

The transparency of the video (used by extensions with camera input). This property is global to the project and stored in the stage.

Type:
  • number

visible :boolean

Whether the rendered target is currently visible.

Type:
  • boolean

volume :number

Loudness for sound playback for this target, as a percentage.

Type:
  • number

x :Number

Scratch X coordinate. Currently should range from -240 to 240.

Type:
  • Number

y :number

Scratch Y coordinate. Currently should range from -180 to 180.

Type:
  • number

Methods

_getRenderedDirectionAndScale() → {object.<string, number>}

Get the rendered direction and scale, after applying rotation style.

Returns:

Direction and scale to render.

Type
object.<string, number>

addCostume(costumeObjectnon-null, indexnullable)

Add a costume, taking care to avoid duplicate names.

Parameters:
Name Type Attributes Description
costumeObject object

Object representing the costume.

index int <nullable>

Index at which to add costume

addSound(soundObjectnon-null, indexnullable)

Add a sound, taking care to avoid duplicate names.

Parameters:
Name Type Attributes Description
soundObject object

Object representing the sound.

index int <nullable>

Index at which to add costume

clearEffects()

Clear all graphic effects on this rendered target.

colorIsTouchingColor(targetRgb, maskRgb) → {Promise.<boolean>}

Return whether rendered target's color is touching a color.

Parameters:
Name Type Description
targetRgb object

{Array.} [r,g,b], values between 0-255.

maskRgb object

{Array.} [r,g,b], values between 0-255.

Returns:

True iff the color is touching the color.

Type
Promise.<boolean>

deleteCostume(index) → (nullable) {object}

Delete a costume by index.

Parameters:
Name Type Description
index number

Costume index to be deleted

Returns:

The costume that was deleted or null if the index was out of bounds of the costumes list or this target only has one costume.

Type
object

deleteSound(index) → {object}

Delete a sound by index.

Parameters:
Name Type Description
index number

Sound index to be deleted

Returns:

The deleted sound object, or null if no sound was deleted.

Type
object

dispose()

Dispose, destroying any run-time properties.

duplicate() → {RenderedTarget}

Make a duplicate using a duplicate sprite.

Returns:

New clone.

Type
RenderedTarget

getBounds() → (nullable) {object}

Return the rendered target's tight bounding box. Includes top, left, bottom, right attributes in Scratch coordinates.

Returns:

Tight bounding box, or null.

Type
object

getBoundsForBubble() → (nullable) {object}

Return the bounding box around a slice of the top 8px of the rendered target. Includes top, left, bottom, right attributes in Scratch coordinates.

Returns:

Tight bounding box, or null.

Type
object

getCostumeIndexByName(costumeNamenullable) → {number}

Get a costume index of this rendered target, by name of the costume.

Parameters:
Name Type Attributes Description
costumeName string <nullable>

Name of a costume.

Returns:

Index of the named costume, or -1 if not present.

Type
number

getCostumes() → {Array.<object>}

Get full costume list

Returns:

list of costumes

Type
Array.<object>

getCurrentCostume() → {object}

Get a costume of this rendered target by id.

Returns:

current costume

Type
object

getName() → {string}

Return the human-readable name for this rendered target, e.g., the sprite's name.

Returns:

Human-readable name.

Type
string

getSounds() → {Array.<object>}

Get full sound list

Returns:

list of sounds

Type
Array.<object>

goBackwardLayers(nLayers)

Move backward a number of layers.

Parameters:
Name Type Description
nLayers number

How many layers to go backward.

goBehindOther(othernon-null)

Move behind some other rendered target.

Parameters:
Name Type Description
other RenderedTarget

Other rendered target to move behind.

goForwardLayers(nLayers)

Move forward a number of layers.

Parameters:
Name Type Description
nLayers number

How many layers to go forward.

goToBack()

Move to the back layer.

goToFront()

Move to the front layer.

initAudio()

Initialize the audio player for this sprite or clone.

initDrawable(layerGroup)

Create a drawable with the this.renderer.

Parameters:
Name Type Description
layerGroup boolean

The layer group this drawable should be added to

isSprite() → {boolean}

Return whether this rendered target is a sprite (not a clone, not the stage).

Returns:

True if not a clone and not the stage.

Type
boolean

isTouchingColor(rgb) → {Promise.<boolean>}

Return whether touching a color.

Parameters:
Name Type Description
rgb Array.<number>

[r,g,b], values between 0-255.

Returns:

True iff the rendered target is touching the color.

Type
Promise.<boolean>

isTouchingEdge() → {boolean}

Return whether touching a stage edge.

Returns:

True iff the rendered target is touching the stage edge.

Type
boolean

isTouchingObject(requestedObject) → {boolean}

Return whether this target is touching the mouse, an edge, or a sprite.

Parameters:
Name Type Description
requestedObject string

an id for mouse or edge, or a sprite name.

Returns:

True if the sprite is touching the object.

Type
boolean

isTouchingPoint(x, y) → {boolean}

Return whether touching a point.

Parameters:
Name Type Description
x number

X coordinate of test point.

y number

Y coordinate of test point.

Returns:

True iff the rendered target is touching the point.

Type
boolean

isTouchingSprite(spriteName) → {boolean}

Return whether touching any of a named sprite's clones.

Parameters:
Name Type Description
spriteName string

Name of the sprite.

Returns:

True iff touching a clone of the sprite.

Type
boolean

keepInFence(newX, newY, optFenceopt) → {Array.<number>}

Keep a desired position within a fence.

Parameters:
Name Type Attributes Description
newX number

New desired X position.

newY number

New desired Y position.

optFence object <optional>

Optional fence with left, right, top bottom.

Returns:

Fenced X and Y coordinates.

Type
Array.<number>

makeClone() → {RenderedTarget}

Make a clone, copying any run-time properties. If we've hit the global clone limit, returns null.

Returns:

New clone.

Type
RenderedTarget

onGreenFlag()

Called when the project receives a "green flag." For a rendered target, this clears graphic effects.

onStopAll()

Called when the project receives a "stop all" Stop all sounds and clear graphic effects.

postSpriteInfo(data)

Post/edit sprite info.

Parameters:
Name Type Description
data object

An object with sprite info data to set.

renameCostume(costumeIndex, newName)

Rename a costume, taking care to avoid duplicate names.

Parameters:
Name Type Description
costumeIndex int

the index of the costume to be renamed.

newName string

the desired new name of the costume (will be modified if already in use).

renameSound(soundIndex, newName)

Rename a sound, taking care to avoid duplicate names.

Parameters:
Name Type Description
soundIndex int

the index of the sound to be renamed.

newName string

the desired new name of the sound (will be modified if already in use).

reorderCostume(costumeIndexnon-null, newIndexnon-null) → {boolean}

Reorder costume list by moving costume at costumeIndex to newIndex.

Parameters:
Name Type Description
costumeIndex number

Index of the costume to move.

newIndex number

New index for that costume.

Returns:

If a change occurred (i.e. if the indices do not match)

Type
boolean

reorderSound(soundIndexnon-null, newIndexnon-null) → {boolean}

Reorder sound list by moving sound at soundIndex to newIndex.

Parameters:
Name Type Description
soundIndex number

Index of the sound to move.

newIndex number

New index for that sound.

Returns:

If a change occurred (i.e. if the indices do not match)

Type
boolean

setCostume(index)

Set the current costume.

Parameters:
Name Type Description
index number

New index of costume.

setDirection(directionnon-null)

Set the direction.

Parameters:
Name Type Description
direction number

New direction.

setDraggable(draggablenon-null)

Set draggability; i.e., whether it's able to be dragged in the player

Parameters:
Name Type Description
draggable boolean

True if should be draggable.

setEffect(effectNamenon-null, valuenon-null)

Set a particular graphic effect value.

Parameters:
Name Type Description
effectName string

Name of effect (see RenderedTarget.prototype.effects).

value number

Numerical magnitude of effect.

setRotationStyle(rotationStylenon-null)

Update the rotation style.

Parameters:
Name Type Description
rotationStyle string

New rotation style.

setSay(typenullable, messagenullable)

Set a say bubble.

Parameters:
Name Type Attributes Description
type string <nullable>

Type of say bubble: "say", "think", or null.

message string <nullable>

Message to put in say bubble.

setSize(sizenon-null)

Set size, as a percentage of the costume size.

Parameters:
Name Type Description
size number

Size of rendered target, as % of costume size.

setVisible(visiblenon-null)

Set visibility; i.e., whether it's shown or hidden.

Parameters:
Name Type Description
visible boolean

True if should be shown.

setXY(xnon-null, ynon-null, forcenullable)

Set the X and Y coordinates.

Parameters:
Name Type Attributes Description
x number

New X coordinate, in Scratch coordinates.

y number

New Y coordinate, in Scratch coordinates.

force boolean <nullable>

Force setting X/Y, in case of dragging

startDrag()

Put the sprite into the drag state. While in effect, setXY must be forced

stopDrag()

Remove the sprite from the drag state.

toJSON() → {object}

Serialize sprite info, used when emitting events about the sprite

Returns:

Sprite data as a simple object

Type
object

updateAllDrawableProperties()

Update all drawable properties for this rendered target. Use when a batch has changed, e.g., when the drawable is first created.