Compare commits
3 Commits
f3b63e0311
...
1a3ce1fe97
Author | SHA1 | Date |
---|---|---|
Alexander Popov | 1a3ce1fe97 | |
Alexander Popov | bdec83fd32 | |
Alexander Popov | cc8a51749a |
23
src/main.js
23
src/main.js
|
@ -7,8 +7,8 @@ export class App {
|
||||||
#version;
|
#version;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
w,
|
width,
|
||||||
h,
|
height,
|
||||||
options = {
|
options = {
|
||||||
backgroundColor: '#ffcc68',
|
backgroundColor: '#ffcc68',
|
||||||
welcome: true,
|
welcome: true,
|
||||||
|
@ -16,12 +16,12 @@ export class App {
|
||||||
) {
|
) {
|
||||||
this.#version = 'beeeeeeta';
|
this.#version = 'beeeeeeta';
|
||||||
|
|
||||||
|
// Create CANVAS element
|
||||||
this.view = document.createElement('canvas');
|
this.view = document.createElement('canvas');
|
||||||
|
|
||||||
this.canvas = this.view;
|
this.canvas = this.view;
|
||||||
this.context = this.canvas.getContext('2d');
|
this.context = this.canvas.getContext('2d');
|
||||||
this.options = options;
|
|
||||||
|
|
||||||
|
this.options = options;
|
||||||
// check options || FIXIT:
|
// check options || FIXIT:
|
||||||
if (typeof this.options.backgroundColor === 'undefined') {
|
if (typeof this.options.backgroundColor === 'undefined') {
|
||||||
this.options.backgroundColor = '#ffcc68';
|
this.options.backgroundColor = '#ffcc68';
|
||||||
|
@ -30,8 +30,7 @@ export class App {
|
||||||
this.options.welcome = true;
|
this.options.welcome = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.scene = new Scene(this.canvas, this.context, w, h);
|
this.scene = new Scene(this.canvas, this.context, width, height);
|
||||||
Settings.prevTime = Date.now();
|
|
||||||
|
|
||||||
const logStrings = [
|
const logStrings = [
|
||||||
'ujs engine',
|
'ujs engine',
|
||||||
|
@ -47,7 +46,9 @@ export class App {
|
||||||
}
|
}
|
||||||
|
|
||||||
Pointer.init();
|
Pointer.init();
|
||||||
|
Settings.fpsPrevTime = Date.now();
|
||||||
|
|
||||||
|
// Start :)
|
||||||
this.run();
|
this.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,18 +59,14 @@ export class App {
|
||||||
Settings.fpsPrevTime = fpsNewTime;
|
Settings.fpsPrevTime = fpsNewTime;
|
||||||
Settings.fps = Math.round(1 / Settings.fpsDelta);
|
Settings.fps = Math.round(1 / Settings.fpsDelta);
|
||||||
|
|
||||||
// clear canvas
|
// Clear canvas
|
||||||
this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
||||||
|
|
||||||
// fill canvas
|
// Fill canvas by default background color
|
||||||
this.context.fillStyle = this.options.backgroundColor;
|
this.context.fillStyle = this.options.backgroundColor;
|
||||||
this.context.fillRect(0, 0, this.canvas.width, this.canvas.height);
|
this.context.fillRect(0, 0, this.canvas.width, this.canvas.height);
|
||||||
|
|
||||||
// draw border
|
// Draw scene
|
||||||
this.context.strokeStyle = '#101024';
|
|
||||||
this.context.lineWidth = 1;
|
|
||||||
this.context.strokeRect(5, 5, this.canvas.width - 10, this.canvas.height - 10);
|
|
||||||
|
|
||||||
this.scene.run();
|
this.scene.run();
|
||||||
|
|
||||||
requestAnimationFrame(this.run);
|
requestAnimationFrame(this.run);
|
||||||
|
|
|
@ -65,6 +65,7 @@ export class Sprite {
|
||||||
this.angle = 0;
|
this.angle = 0;
|
||||||
this.src = src;
|
this.src = src;
|
||||||
this.srcOld = this.src;
|
this.srcOld = this.src;
|
||||||
|
this.ticker = null;
|
||||||
|
|
||||||
this.loaded = false;
|
this.loaded = false;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue