Space

Space is an abstract class that represents a general context for expressing Pts. It's extended through subclasses such as CanvasSpace and SVGSpace. You can also create your own extension of Space. See Space guide for details.

Class in src/Space.ts

Accessors

GET center : Pt

The center of this space's bounding box.

GET SET customRendering : Fn(context:any, self:Space)

Set a custom rendering function fn(graphics_context, canvas_space) if needed.

GET height : number

The height of this space's bounding box.

GET innerBound : Bound

The inner bounding box of the space, excluding its positions.

GET isPlaying : boolean

Indicate whether the animation is playing.

GET outerBound : Bound

The outer bounding box which includes its positions.

GET size : Pt

The size of this space's bounding box.

GET width : number

The width of this space's bounding box.

Methods

add ( p )

Add an IPlayer object or a AnimateCallbackFn callback function to handle events in this Space. An IPlayer is an object with the following callback functions:

  • required: animate: fn( time, ftime, space )
  • optional: start: fn(bound, space)
  • optional: resize: fn( size, event )
  • optional: action: fn( type, x, y, event ) Subclasses of Space may define other callback functions.
parameters
p: IPlayer | AnimateCallbackFn

returns
this

source

clear ( )

clear all contents in the space. To be implemented in subclasses.

returns
this

source

getForm ( )

Get a default form for drawing in this space. To be implemented in subclasses.

returns
Form

source

minFrameTime ( ms )

Set a minimum frame time

parameters
ms: number (default value: 0)

at least this amount of miniseconds must have elapsed before frame advances

returns
void

source

pause ( toggle )

Pause the animation.

parameters
toggle: boolean (default value: false)

a boolean value to set if this function call should be a toggle (between pause and resume)

returns
this

source

play ( time )

Main play loop. This implements window.requestAnimationFrame and calls it recursively. You may override this play() function to implement your own animation loop.

parameters
time: number (default value: 0)

current time

returns
this

source

playItems ( time )

Main animate function. This calls all the items to perform.

parameters
time: number

current time

returns
void

source

playOnce ( duration )

Play animation loop once. Optionally set a duration time to play for that specific duration.

parameters
duration: number (default value: 0)

a value in millisecond to specify a time period to play before stopping, or -1 to play forever

returns
this

source

refresh ( b )

Set whether the rendering should be repainted on each frame.

parameters
b: boolean

a boolean value to set whether to repaint each frame

returns
this

source

remove ( player )

Remove a player from this Space.

parameters
player: IPlayer

an IPlayer that has an animateID property

returns
this

source

removeAll ( )

Remove all players from this Space.

returns
this

source

render ( context )

Custom rendering.

parameters
context: any

rendering context

returns
this

source

replay ( )

Replay the animation after Space.stop. This resets the end-time counter. You may also use Space.pause and resume for temporary pause.

returns
void

source

resize ( b, evt )

Resize the space. To be implemented in subclasses.

parameters
b: Bound

a Bound representing the position and size of the space

evt: Event

event

returns
this

source

resume ( )

Resume the pause animation.

returns
this

source

stop ( t )

Specify when the animation should stop: immediately, after a time period, or never stops.

parameters
t: number (default value: 0)

a value in millisecond to specify a time period to play before stopping, or -1 to play forever, or 0 to end immediately. Default is 0 which will stop the animation immediately.

returns
this

source