1.0.2 • Published 11 months ago
@h4v0c/sg2d v1.0.2
sg2d
A simple scene-graph that works with @h4v0c/renderer2d
Classes:
Base
(abstract
,extends
EventEmitter): The base class to all nodes.- Properties:
id
(readonly
,UID
): unique id set by @h4v0c/uidtype
(readonly
,string
): node type, set bythis.constructor.name
name
(string
): user mutable name for the node, defaults tothis.constructor.name
- Properties:
Node
(extends Base
):- Properties:
position
(vec2
): relative positionrotation
: (number
): relative rotation (still WiP)scale
: (vec2
): relative scalelocalMatrix
: (mat3
): the local view matrixworldMatrix
: (mat3
) = the world view matrixparent
: (Node
): this node's parentNode
children
: (Node[]
):Node
children of this node
- Methods:
setParent
(parent
:Node
): set this node's parent toparent
updateLocalMatrix
(): updates this node'slocalMatrix
, typically only called byupdateWorldMatrix
(see below)updateWorldMatrix
(otherMatrix
?:mat3
): callsupdateLocalMatrix
and updated this node'sworldMatrix
, including mutating by parent node'sworldMatrix
.otherMatrix
is an optional matrix that can be set to further mutate this node and it's child nodes, typically used by theCamera
node to provide aprojectionMatrix
.update
(time
:number
,deltaTime
:number
): updates properties and childrenrender
(renderer
:Renderer
, ...args
:any[]
): renders the node and children
- Properties:
Scene
(extendsNode
):- Methods:
render
(renderer
:Renderer
,time
:number
,deltaTime
:number
,camera
?:Camera
): Renders the entire scene, including children, passing all required parameters to it's children. The optional parameter,camera
is used only if aCamera
is created, and will calculate and include it'sprojectionMatrix
in the scene'sworldMatrix
(which is then used for it's children).
- Methods:
Camera
(extendsNode
):- Properties:
projectionMatrix
(mat3
): The camera'sprojectionMatrix
, calculated byScene.render
(if included). It is the inverted form of it'sworldMatrix
, after it'sworldMatrix
is calculated.
- Properties:
Sprite
(extendsNode
):- Properties:
_texture
(protected
,Texture
): holds theTexture
dataregion
(vec4
): defines the rectangle area of_texture
to drawcentered
(boolean
): true means that the position of the drawn texture will be half it's width and height, false means the position will be the top-left of the texture.
- Properties:
AnimatedSprite
(extendsSprite
):- Properties:
animating
(boolean
, default:true
): animation is on or offanimationSpeed
(number
, default:250
): time before next frameframeIndex
(number
, default:0
): current frameframes
: (vec4[]
, default:[]
): all frames (aframe
is like aregion
fromSprite
)_frameTime
(private
,number
, default:0
): holds the current time
- Properties:
TileMap
(extendsNode
):
(MORE TO COME)