ujs/src/js/scene.js

48 lines
1.1 KiB
JavaScript
Raw Normal View History

2023-02-16 00:04:40 +03:00
import { Pointer } from './pointer.js';
export class Scene {
2023-04-06 15:03:09 +03:00
#canvas;
#context;
#scene;
constructor(canvas, context, width, height) {
this.#canvas = canvas;
this.#context = context;
2023-04-06 14:44:41 +03:00
this.init(width, height);
2023-02-16 00:04:40 +03:00
}
2023-04-06 14:44:41 +03:00
init = async (width, height) => {
this.setScreenSize(width, height);
2023-02-16 00:04:40 +03:00
}
2023-04-06 14:54:58 +03:00
#clearCanvas() {
2023-04-06 15:03:09 +03:00
this.#context.clearRect(0, 0, this.#canvas.width, this.#canvas.height);
2023-04-06 14:54:58 +03:00
}
2023-02-16 00:04:40 +03:00
run() {
2023-04-06 14:44:41 +03:00
// clear canvas
2023-04-06 14:54:58 +03:00
this.#clearCanvas();
2023-04-06 15:03:09 +03:00
this.#scene();
}
2023-04-06 14:52:58 +03:00
2023-04-06 15:03:09 +03:00
#scene() {
2023-04-06 14:52:58 +03:00
// fill canvas
2023-04-06 15:03:09 +03:00
this.#context.fillStyle = '#523c4e';
this.#context.fillRect(0, 0, this.#canvas.width, this.#canvas.height);
2023-04-06 14:52:58 +03:00
// draw border
2023-04-06 15:03:09 +03:00
this.#context.strokeStyle = '#8bd0ba';
this.#context.lineWidth = 1;
this.#context.strokeRect(5, 5, this.#canvas.width - 10, this.#canvas.height - 10);
2023-04-06 14:52:58 +03:00
// draw rect in center
2023-04-06 15:03:09 +03:00
this.#context.fillStyle = '#d44e52';
this.#context.fillRect(this.#canvas.width / 2 - 50, this.#canvas.height / 2 - 50, 100, 100);
2023-02-16 00:04:40 +03:00
}
2023-04-06 14:44:41 +03:00
setScreenSize(w, h) {
2023-04-06 15:03:09 +03:00
this.#canvas.width = w;
this.#canvas.height = h;
2023-02-16 00:04:40 +03:00
}
}