Skip to content

Sprites

Overview

Meant for displaying a large amount of high-performance instances of sprites. See https://github.com/phetsims/scenery/issues/990 for more information.

@author Jonathan Olson <jonathan.olson@colorado.edu>

Class Sprites

import { Sprites } from 'scenerystack/scenery';

Constructor

new Sprites( providedOptions? : SpritesOptions )

Instance Methods

setCanvasBounds( selfBounds : Bounds2 )

Sets the bounds that are used for layout/repainting.

These bounds should always cover at least the area where the Sprites will draw in. If this is violated, this node may be partially or completely invisible in Scenery's output.

getCanvasBounds() : Bounds2

Returns the previously-set canvasBounds, or Bounds2.NOTHING if it has not been set yet.

canvasPaintSelf( wrapper : CanvasContextWrapper, matrix : Matrix3 )

(protected)

Draws the current Node's self representation, assuming the wrapper's Canvas context is already in the local coordinate frame of this node.

@param wrapper @param matrix - The transformation matrix already applied to the context.

containsPointSelf( point : Vector2 ) : boolean

Computes whether the provided point is "inside" (contained) in this Node's self content, or "outside".

@param point - Considered to be in the local coordinate frame

getSpriteInstanceFromPoint( point : Vector2 ) : SpriteInstance | null

Finds which sprite instance is on top under a certain point (or null if none are).

getSelfShape() : Shape

Returns a Shape that represents the area covered by containsPointSelf.

isPainted() : boolean

Whether this Node itself is painted (displays something itself).

invalidatePaint()

Should be called when this node needs to be repainted. When not called, Scenery assumes that this node does NOT need to be repainted (although Scenery may repaint it due to other nodes needing to be repainted).

This sets a "dirty" flag, so that it will be repainted the next time it would be displayed.

mutate( options? : SpritesOptions ) : this

Type SpritesOptions

import type { SpritesOptions } from 'scenerystack/scenery';
  • sprites?: Sprite[]
    Provide a fixed set of Sprite objects that will be used for this node. Currently, it cannot be modified after construction for simplicity of the implementation.
  • spriteInstances?: SpriteInstance[]
    A reference to an Array of instances. This array can be (and should be) manipulated to adjust the displayed instances (their sprites/transforms/etc.). After this has been adjusted, invalidatePaint() should be called on the Sprites node.
  • hitTestSprites?: boolean
    Whether individual sprites will be hit-tested to determine what is a contained point (for hit testing, etc.). If false, the canvasBounds will be used for hit testing.
  • canvasBounds?: Bounds2
  • & NodeOptions

Source Code

See the source for Sprites.ts in the scenery repository.