-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBackground.java
More file actions
48 lines (37 loc) · 1.12 KB
/
Background.java
File metadata and controls
48 lines (37 loc) · 1.12 KB
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
package com.mygdx.game;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Vector;
import com.badlogic.gdx.math.Vector2;
public class Background {
class BGPicture {
private Texture tx;
private Vector2 pos;
public BGPicture(Vector2 pos) {
tx = new Texture("back.png");
this.pos = pos;
}
}
private int speed;
private BGPicture[] backs;
public Background() {
speed = 3;
backs = new BGPicture[2];
backs[0] = new BGPicture(new Vector2(0, 0));
backs[1] = new BGPicture(new Vector2(800, 0));
}
public void render(SpriteBatch batch) {
for(int i = 0; i < backs.length; i++) {
batch.draw(backs[i].tx, backs[i].pos.x, backs[i].pos.y);
}
}
public void update() {
for(int i = 0; i < backs.length; i++) {
backs[i].pos.x -= speed;
}
if (backs[0].pos.x < -800) {
backs[0].pos.x = 0;
backs[1].pos.x = 800;
}
}
}