-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCanvas.js
35 lines (27 loc) · 859 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
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.drawImage = function(image, position, origin){
if(!position){
position = new vector2();
}
if(!origin){
origin = new Vector2();
}
this._canvasContext.save();
this._canvasContext.translate(position.x,position.y);
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.drawImage(image, {x:0,y:0});
// //Canvas.clear();
// },1000);