1.0.2 • Published 2 years ago
@h4v0c/sg2d v1.0.2
sg2d
A simple scene-graph that works with @h4v0c/renderer2d
Classes:
Base(abstract,extendsEventEmitter): The base class to all nodes.- Properties:
id(readonly,UID): unique id set by @h4v0c/uidtype(readonly,string): node type, set bythis.constructor.namename(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 parentNodechildren: (Node[]):Nodechildren of this node
- Methods:
setParent(parent:Node): set this node's parent toparentupdateLocalMatrix(): updates this node'slocalMatrix, typically only called byupdateWorldMatrix(see below)updateWorldMatrix(otherMatrix?:mat3): callsupdateLocalMatrixand updated this node'sworldMatrix, including mutating by parent node'sworldMatrix.otherMatrixis an optional matrix that can be set to further mutate this node and it's child nodes, typically used by theCameranode 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,camerais used only if aCamerais created, and will calculate and include it'sprojectionMatrixin 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'sworldMatrixis calculated.
- Properties:
Sprite(extendsNode):- Properties:
_texture(protected,Texture): holds theTexturedataregion(vec4): defines the rectangle area of_textureto 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 (aframeis like aregionfromSprite)_frameTime(private,number, default:0): holds the current time
- Properties:
TileMap(extendsNode):
(MORE TO COME)