-
Notifications
You must be signed in to change notification settings - Fork 1
/
Background.js
50 lines (39 loc) · 1.17 KB
/
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
class BackgroundPart extends PIXI.Sprite {
constructor(arg) {
super(resources[arg].texture);
this.initProportion = this.width / this.height;
this.height = app.renderer.height;
this.width = this.height * this.initProportion;
app.stage.addChild(this);
}
}
class StaticBackground extends PIXI.Sprite {
constructor(arg) {
super(resources[arg].texture);
this.anchor.set(0, 0);
this.initProportion = this.width / this.height;
this.height = app.renderer.height;
this.width = this.height * this.initProportion;
app.stage.addChild(this);
}
}
class Background {
constructor(img="images/background/1.png", speed=0) {
this.parts = [
new BackgroundPart(img),
new BackgroundPart(img)
];
// this.parts[1].scale.x = -1;
this.img = img;
this.speed = speed;
}
nextStep(xSpeedFactor) {
for (let partN in this.parts) {
const part = this.parts[partN];
part.x -= this.speed*xSpeedFactor;
if (part.x < -part.width) {
part.x = part.width;
}
}
}
}