Application
Extends:
Create a new application
Example:
let app = new Application({ container: document.getElementById('my-canvas'), width: 500, height: 300 });
Constructor Summary
Public Constructor | ||
public |
constructor(options: Object) |
Member Summary
Public Members | ||
public |
background: hex Canvas background color |
|
public |
canvas: HTMLCanvasElement |
|
public |
|
|
public |
|
|
public |
Current layer rendered |
|
public |
Canvas height (default window height) |
|
public |
|
|
public |
List of layers |
|
public |
|
|
public |
|
|
public |
Object of options |
|
public |
|
|
public |
Canvas width (default window width) |
Method Summary
Public Methods | ||
public |
Add layer to application |
|
public |
changeLayer(name: String) Switch the current layer |
Protected Methods | ||
protected |
ready() Start timer and called application ready function |
|
protected |
Callback called at every frame to render models |
|
protected |
Callback called at every frame to calculate models x,y positions |
Inherited Summary
From class Drawer | ||
public |
|
|
public |
Reset canvas zone |
|
public |
Add models to debug |
|
public |
drawCircle(x: number, y: number, radius: number, size: number, color: string, start: number, end: number) Draw a circle |
|
public |
drawFillCircle(x: number, y: number, radius: number, color: string, lineSize: number, lineColor: string, start: number, end: number) Draw a fill circle |
|
public |
drawFillRect(x: number, y: number, width: number, height: number, color: string, lineSize: number, lineColor: string) Draw a fill rectangle |
|
public |
drawImage(source: *, x: number, y: number, width: number, height: number, destinationX: number, destinationY: number, destinationWidth: number, destinationHeight: number) Draw images |
|
public |
Draw a line |
|
public |
Draw model |
|
public |
Draw a rectangle |
|
public |
drawText(text: string, x: number, y: number, size: string, font: string, color: string, style: string, align: string, baseline: string): Object Draw a text |
|
public |
Restore last saved context |
|
public |
rotateModel(model: Model, deg: float, pivotX: number, pivotY: number): Drawer Rotate model |
|
public |
Save context |
Public Constructors
public constructor(options: Object) source
Override:
Drawer#constructorParams:
Name | Type | Attribute | Description |
options | Object |
|
|
options.container | HTMLElement |
|
HTML container (default: body element) |
options.width | number |
|
canvas width (default: window width) |
options.height | number |
|
canvas height (default: window height) |
options.background | string |
|
canvas background (default: 0xffffff) |
options.create | function |
|
called to load assets |
options.render | function |
|
called at every frame |
options.ready | function |
|
called when application is ready (need to use loader) |
Example:
const app = new Application({
width: 500,
height: 500,
container: document.getElementById('my-canvas'),
create: function() {
loader.add('images/player-sprite.png', 'player');
},
ready: function() {
this.addLayer(layer, 'home');
}
});
Public Members
public canvas: HTMLCanvasElement source
public context: CanvasRenderingContext2D source
Public Methods
public addLayer(layer: Object, name: String) source
Add layer to application
Example:
const layer = {
create: function() {
this.player = new Model(this.width / 2, this.height / 2, 100, 100);
},
step: function() {
this.player.x += 1;
if (this.player.x > this.width) {
this.player.x = -100;
}
},
render: function() {
this.clearLayer();
this.drawRect(this.player.x, this.player.y, this.player.width, this.player.height);
}
};
app.addLayer('scene1', layer);
public changeLayer(name: String) source
Switch the current layer
Params:
Name | Type | Attribute | Description |
name | String |