Description

Create an entity. An entity is an abstract element. It allows to define its position, its hitbox without display on the screen. This class is linked to a model for the calculation of positions and an element (el property) to display

Usage

Constructor

  • stage {CanvasEngine.Element}

    Stage element

Example

In ready method

 this.entity = Class.New("Entity", [stage]);
 this.entity.rect(100);
 this.entity.position(10, 10);
 this.entity.el.fillStyle = "red";
 this.entity.el.fillRect(0, 0, 100, 100);
 stage.append(this.entity.el);

In render method

 this.entity.move(5, null);
 this.entity.hit("over", [this.other_entity], function(el) {  // other_entity is another instance of the Entity class
    el.opacity = .5;
});

Methods

position

Change the position of the entity and the element. Returns object {x: , y: }

move

Move the position of the entity and the element. Returns object {x: , y: }

polygon

Polygons define the entity

rect

Define the polygon as a rectangle. The element will take up his new dimensions (`width` and `height` properties). If `x` and `y` are undefined, they will default 0. If only one parameter is defined, the shape is a square with the given width

hit

Calls the function when two or more entities come into colision

Discussion