-
Notifications
You must be signed in to change notification settings - Fork 0
/
Canvas.js
37 lines (30 loc) · 911 Bytes
/
Canvas.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
function Canvas2d() {
this._canvas = document.getElementById('screen');
this._canvasContext = this._canvas.getContext('2d');
}
Canvas2d.prototype.clear = function() {
this._canvasContext.clearRect(0, 0, this._canvas.width, this._canvas.height);
};
Canvas2d.prototype.drawIamge = function(image, position, origin, rotation = 0) {
if (!position) {
position = new Vector2();
}
if (!origin) {
origin = new Vector2();
}
this._canvasContext.save();
this._canvasContext.translate(position.x, position.y);
this._canvasContext.rotate(rotation);
this._canvasContext.drawImage(image, -origin.x, -origin.y);
this._canvasContext.restore();
};
let Canvas = new Canvas2d();
// Testing
let image = new Image();
image.src = './assets/sprites/spr_background4.png';
setTimeout(() => {
Canvas.drawIamge(image, {
x: 0,
y: 0
});
}, 1000);