Skip to content

Creating own GameObject

Tymon Woźniak edited this page Apr 21, 2023 · 1 revision

Creating own GameObject

First you need to choose what type of object you need.

GameObject Class Purpose
GameObject Plain game object
DrawableGameObject Drawable game object
ClickableGameObject Clickable and drawable game object
Shape Clickable, drawable shape on canvas
Sprite Clickable, drawable image on canvas

Creating class

class myGameObject extends JSGL.GAME_OBJECT {}

Example

class MovingRect extends JSGL.Shape {
    Start(){
        this.transform.set(game.GetRandomPosition());
        this.properties.color = 'red';
        this.properties.border = true;
        this.properties.borderColor = 'black';
    }
    Update(event){
        this.transform.translate(this.transform.forward.multiply(event.deltaTime));
    }
    OnMouseClick = () => JSGL.log('mouse click');
    OnMouseDown = () => JSGL.log('mouse down');
    OnMouseUp = () => JSGL.log('mouse up');
    OnMouseHoverStart(){
        JSGL.log('mouse hover start');
        this.properties.color = 'blue';
    }
    OnMouseHoverEnd(){
        JSGL.log('mouse hover end');
        this.properties.color = 'red';
    }
}
Clone this wiki locally