forked from buckyroberts/Source-Code-from-Tutorials
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMyGdxGame.java
More file actions
101 lines (80 loc) · 2.81 KB
/
Copy pathMyGdxGame.java
File metadata and controls
101 lines (80 loc) · 2.81 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package com.thenewboston.buckyblaster;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.input.GestureDetector;
import com.badlogic.gdx.input.GestureDetector.GestureListener;
import com.badlogic.gdx.math.Vector2;
public class MyGdxGame extends ApplicationAdapter implements GestureListener {
private SpriteBatch batch;
private OrthographicCamera camera;
private Texture texture;
private Sprite sprite;
@Override
public void create() {
batch = new SpriteBatch();
//Orthographic for 2D, pass in width and height of area to display
camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
texture = new Texture(Gdx.files.internal("worldMap.png"));
sprite = new Sprite(texture);
//This would position the bottom left corner in the middle of the screen
//sprite.setPosition(0, 0);
//Move it down and left by half its length and width to center
sprite.setPosition(-sprite.getWidth() / 2, -sprite.getHeight() / 2);
Gdx.input.setInputProcessor(new GestureDetector(this));
}
@Override
public void dispose() {
batch.dispose();
texture.dispose();
}
@Override
public void render() {
Gdx.gl.glClearColor(1, 1, 1, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
//Use this camera to determine what to draw on the screen
batch.setProjectionMatrix(camera.combined);
batch.begin();
sprite.draw(batch);
batch.end();
}
//Change the cameras coordinates and update the view
@Override
public boolean pan(float x, float y, float deltaX, float deltaY) {
camera.translate(-deltaX, deltaY);
camera.update();
return true;
}
@Override
public boolean touchDown(float x, float y, int pointer, int button) {
return false;
}
@Override
public boolean tap(float x, float y, int count, int button) {
return false;
}
@Override
public boolean longPress(float x, float y) {
return false;
}
@Override
public boolean fling(float velocityX, float velocityY, int button) {
return false;
}
@Override
public boolean panStop(float x, float y, int pointer, int button) {
return false;
}
@Override
public boolean zoom(float initialDistance, float distance) {
return false;
}
@Override
public boolean pinch(Vector2 initialPointer1, Vector2 initialPointer2, Vector2 pointer1, Vector2 pointer2) {
return false;
}
}