-
Notifications
You must be signed in to change notification settings - Fork 0
/
Background.js
26 lines (19 loc) · 905 Bytes
/
Background.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
function Background(image) {
this.image = image; //the source photo
//placeholder variables
this.cx = 0;
this.cy = 0;
}
Background.prototype.draw = function(ctx) {
// Draw the camera's view wrapped to this.image.width...
// Find where the camera is on the background image
const cameraLocationInImage = g_camera.xView % this.image.width;
// Logic for looping the background
const firstImageWidth = this.image.width - cameraLocationInImage;
const restWidth = g_canvas.width - firstImageWidth;
ctx.drawImage(this.image, cameraLocationInImage, 0, firstImageWidth, g_canvas.height, 0, 0, firstImageWidth, g_canvas.height);
ctx.drawImage(this.image, 0, 0, restWidth, g_canvas.height, firstImageWidth, 0, restWidth, g_canvas.height);
}
Background.prototype.update = function(du) {
//calling the draw function again redrawing it at the new location
}