Skip to content

Commit 24ebdbb

Browse files
committed
Cleans unused code, includes assets
1 parent 0e36282 commit 24ebdbb

File tree

8 files changed

+175
-173
lines changed

8 files changed

+175
-173
lines changed

assets/add.png

878 Bytes
Loading

assets/pin.png

1.95 KB
Loading

assets/sub.png

867 Bytes
Loading
+9-149
Original file line numberDiff line numberDiff line change
@@ -1,158 +1,18 @@
11
package no.mehl.libgdx.map.example;
22

3-
import com.badlogic.gdx.*;
4-
import com.badlogic.gdx.graphics.GL20;
5-
import com.badlogic.gdx.graphics.OrthographicCamera;
6-
import com.badlogic.gdx.graphics.Texture;
7-
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
8-
import com.badlogic.gdx.graphics.g2d.TextureRegion;
9-
import com.badlogic.gdx.input.GestureDetector;
10-
import com.badlogic.gdx.math.Matrix4;
11-
import com.badlogic.gdx.math.Vector2;
12-
import com.badlogic.gdx.math.Vector3;
13-
import com.badlogic.gdx.utils.Logger;
14-
import no.mehl.libgdx.map.cache.MemoryCache;
15-
import no.mehl.libgdx.map.info.CloudmadeTileFactoryInfo;
16-
import no.mehl.libgdx.map.info.MapQuestTileFactoryInfo;
17-
import no.mehl.libgdx.map.info.MapManager;
18-
import no.mehl.libgdx.map.ui.MapListener;
19-
import no.mehl.libgdx.map.ui.MapWidget;
20-
import no.mehl.libgdx.map.util.GeoPosition;
3+
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
4+
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
215

22-
public class MapTest implements ApplicationListener, GestureDetector.GestureListener {
6+
public class MapTest {
237

24-
private Logger logger = new Logger(MapTest.class.getSimpleName(), Logger.INFO);
8+
public static void main(String[] args) {
259

26-
OrthographicCamera camera;
27-
private MapManager mapManager;
10+
LwjglApplicationConfiguration cfg = new LwjglApplicationConfiguration();
11+
cfg.title = "uniquegameidentifaction";
12+
cfg.width = 568;
13+
cfg.height = 1080;
2814

29-
private Texture pin;
30-
private SpriteBatch batch;
31-
private Vector3 pinPos = new Vector3();
3215

33-
private float pinWidth = 0.1f;
34-
private float pinHeight = 0.1f;
35-
36-
private MapListener listener;
37-
private float delta;
38-
39-
@Override
40-
public void create() {
41-
mapManager = new MapManager(new CloudmadeTileFactoryInfo(), null, new MemoryCache(), 512, 512, 0, 0);
42-
listener = new MapListener(mapManager);
43-
Gdx.input.setInputProcessor(new InputMultiplexer(new GestureDetector(this)));
44-
45-
46-
// Tile maps
47-
updatePin();
48-
pin = new Texture(Gdx.files.external("dev/assets/sprites_ui/pin.png"));
49-
50-
batch = new SpriteBatch();
51-
camera = mapManager.getCamera();
52-
}
53-
54-
@Override
55-
public void resize(int width, int height) {
56-
//To change body of implemented methods use File | Settings | File Templates.
57-
}
58-
59-
@Override
60-
public void render() {
61-
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
62-
Gdx.gl.glClearColor(0.3f, 0.3f, 0.7f, 1.0f);
63-
64-
mapManager.update();
65-
66-
TextureRegion map = mapManager.getMapTexture();
67-
batch.begin();
68-
batch.draw(map, Gdx.graphics.getWidth() * 0.5f - map.getRegionWidth() * 0.5f, Gdx.graphics.getHeight()*0.5f - map.getRegionHeight() * 0.5f);
69-
batch.end();
70-
71-
Matrix4 mat = batch.getProjectionMatrix().cpy();
72-
batch.setProjectionMatrix(camera.combined);
73-
batch.begin();
74-
batch.draw(pin, pinPos.x - pinWidth * 0.5f, pinPos.y, pinWidth, -pinHeight);
75-
batch.end();
76-
batch.setProjectionMatrix(mat);
77-
78-
79-
delta += Gdx.graphics.getDeltaTime();
80-
if(delta > 1f) {
81-
logger.info("Current FPS: " + Gdx.graphics.getFramesPerSecond());
82-
delta = 0;
83-
}
84-
}
85-
86-
@Override
87-
public void pause() {
88-
//To change body of implemented methods use File | Settings | File Templates.
89-
}
90-
91-
@Override
92-
public void resume() {
93-
//To change body of implemented methods use File | Settings | File Templates.
94-
}
95-
96-
@Override
97-
public void dispose() {
98-
//To change body of implemented methods use File | Settings | File Templates.
99-
}
100-
101-
// public boolean scrolled(int amount) {
102-
// mapManager.zoomCamera(0.05f * amount);
103-
// return false; //To change body of implemented methods use File | Settings | File Templates.
104-
// }
105-
106-
/** Sets some pin that we have */
107-
private void updatePin() {
108-
Vector2 pos = mapManager.geoInPixels(new GeoPosition(59.9267740, 15.7161670));
109-
pinPos.set(pos.x, pos.y, 0);
110-
}
111-
112-
@Override
113-
public boolean touchDown(float x, float y, int pointer, int button) {
114-
listener.touchDown(null, x, y, pointer, button);
115-
return false;
116-
}
117-
118-
@Override
119-
public boolean tap(float x, float y, int count, int button) {
120-
listener.tap(null, x, y, count, button);
121-
return false;
122-
}
123-
124-
@Override
125-
public boolean longPress(float x, float y) {
126-
listener.longPress(null, x, y);
127-
return false;
128-
}
129-
130-
@Override
131-
public boolean fling(float velocityX, float velocityY, int button) {
132-
listener.fling(null, velocityX, velocityY, button);
133-
return false;
134-
}
135-
136-
@Override
137-
public boolean pan(float x, float y, float deltaX, float deltaY) {
138-
listener.pan(null, x, y, deltaX, -deltaY);
139-
return false;
140-
}
141-
142-
@Override
143-
public boolean panStop(float x, float y, int pointer, int button) {
144-
return false; //To change body of implemented methods use File | Settings | File Templates.
145-
}
146-
147-
@Override
148-
public boolean zoom(float initialDistance, float distance) {
149-
listener.zoom(null, initialDistance, distance);
150-
return false;
151-
}
152-
153-
@Override
154-
public boolean pinch(Vector2 initialPointer1, Vector2 initialPointer2, Vector2 pointer1, Vector2 pointer2) {
155-
listener.pinch(null, initialPointer1, initialPointer2, pointer1, pointer2);
156-
return false;
16+
new LwjglApplication(new MapView(), cfg);
15717
}
15818
}
+157
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
package no.mehl.libgdx.map.example;
2+
3+
import com.badlogic.gdx.*;
4+
import com.badlogic.gdx.graphics.GL20;
5+
import com.badlogic.gdx.graphics.OrthographicCamera;
6+
import com.badlogic.gdx.graphics.Texture;
7+
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
8+
import com.badlogic.gdx.graphics.g2d.TextureRegion;
9+
import com.badlogic.gdx.input.GestureDetector;
10+
import com.badlogic.gdx.math.Matrix4;
11+
import com.badlogic.gdx.math.Vector2;
12+
import com.badlogic.gdx.math.Vector3;
13+
import com.badlogic.gdx.utils.Logger;
14+
import no.mehl.libgdx.map.cache.MemoryCache;
15+
import no.mehl.libgdx.map.info.CloudmadeTileFactoryInfo;
16+
import no.mehl.libgdx.map.info.MapManager;
17+
import no.mehl.libgdx.map.info.MapQuestTileFactoryInfo;
18+
import no.mehl.libgdx.map.ui.MapListener;
19+
import no.mehl.libgdx.map.util.GeoPosition;
20+
21+
public class MapView implements ApplicationListener, GestureDetector.GestureListener {
22+
23+
private Logger logger = new Logger(MapView.class.getSimpleName(), Logger.INFO);
24+
25+
OrthographicCamera camera;
26+
private MapManager mapManager;
27+
28+
private Texture pin;
29+
private SpriteBatch batch;
30+
private Vector3 pinPos = new Vector3();
31+
32+
private float pinWidth = 0.1f;
33+
private float pinHeight = 0.1f;
34+
35+
private MapListener listener;
36+
private float delta;
37+
38+
@Override
39+
public void create() {
40+
mapManager = new MapManager(new MapQuestTileFactoryInfo(), null, new MemoryCache(), 512, 512, 0, 0);
41+
listener = new MapListener(mapManager);
42+
Gdx.input.setInputProcessor(new InputMultiplexer(new GestureDetector(this)));
43+
44+
45+
// Tile maps
46+
updatePin();
47+
pin = new Texture(Gdx.files.internal("assets/pin.png"));
48+
49+
batch = new SpriteBatch();
50+
camera = mapManager.getCamera();
51+
}
52+
53+
@Override
54+
public void resize(int width, int height) {
55+
//To change body of implemented methods use File | Settings | File Templates.
56+
}
57+
58+
@Override
59+
public void render() {
60+
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
61+
Gdx.gl.glClearColor(0.3f, 0.3f, 0.7f, 1.0f);
62+
63+
mapManager.update();
64+
65+
TextureRegion map = mapManager.getMapTexture();
66+
batch.begin();
67+
batch.draw(map, Gdx.graphics.getWidth() * 0.5f - map.getRegionWidth() * 0.5f, Gdx.graphics.getHeight()*0.5f - map.getRegionHeight() * 0.5f);
68+
batch.end();
69+
70+
Matrix4 mat = batch.getProjectionMatrix().cpy();
71+
batch.setProjectionMatrix(camera.combined);
72+
batch.begin();
73+
batch.draw(pin, pinPos.x - pinWidth * 0.5f, pinPos.y, pinWidth, -pinHeight);
74+
batch.end();
75+
batch.setProjectionMatrix(mat);
76+
77+
78+
delta += Gdx.graphics.getDeltaTime();
79+
if(delta > 1f) {
80+
logger.info("Current FPS: " + Gdx.graphics.getFramesPerSecond());
81+
delta = 0;
82+
}
83+
}
84+
85+
@Override
86+
public void pause() {
87+
//To change body of implemented methods use File | Settings | File Templates.
88+
}
89+
90+
@Override
91+
public void resume() {
92+
//To change body of implemented methods use File | Settings | File Templates.
93+
}
94+
95+
@Override
96+
public void dispose() {
97+
//To change body of implemented methods use File | Settings | File Templates.
98+
}
99+
100+
// public boolean scrolled(int amount) {
101+
// mapManager.zoomCamera(0.05f * amount);
102+
// return false; //To change body of implemented methods use File | Settings | File Templates.
103+
// }
104+
105+
/** Sets some pin that we have */
106+
private void updatePin() {
107+
Vector2 pos = mapManager.geoInPixels(new GeoPosition(59.9267740, 15.7161670));
108+
pinPos.set(pos.x, pos.y, 0);
109+
}
110+
111+
@Override
112+
public boolean touchDown(float x, float y, int pointer, int button) {
113+
listener.touchDown(null, x, y, pointer, button);
114+
return false;
115+
}
116+
117+
@Override
118+
public boolean tap(float x, float y, int count, int button) {
119+
listener.tap(null, x, y, count, button);
120+
return false;
121+
}
122+
123+
@Override
124+
public boolean longPress(float x, float y) {
125+
updatePin();
126+
return true;
127+
}
128+
129+
@Override
130+
public boolean fling(float velocityX, float velocityY, int button) {
131+
listener.fling(null, velocityX, velocityY, button);
132+
return false;
133+
}
134+
135+
@Override
136+
public boolean pan(float x, float y, float deltaX, float deltaY) {
137+
listener.pan(null, x, y, deltaX, -deltaY);
138+
return false;
139+
}
140+
141+
@Override
142+
public boolean panStop(float x, float y, int pointer, int button) {
143+
return false; //To change body of implemented methods use File | Settings | File Templates.
144+
}
145+
146+
@Override
147+
public boolean zoom(float initialDistance, float distance) {
148+
listener.zoom(null, initialDistance, distance);
149+
return false;
150+
}
151+
152+
@Override
153+
public boolean pinch(Vector2 initialPointer1, Vector2 initialPointer2, Vector2 pointer1, Vector2 pointer2) {
154+
listener.pinch(null, initialPointer1, initialPointer2, pointer1, pointer2);
155+
return false;
156+
}
157+
}

src/no/mehl/libgdx/map/info/MapManager.java

+1-10
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,8 @@ private TiledMapTileLayer getLayer(int index) {
303303
}
304304

305305
/** Zoom to some level in the tiled map */
306-
public void zoom(float centerX, float centerY, int dZoom) {
306+
public void zoom(int dZoom) {
307307
transition(dZoom);
308-
// camera.position.set(centerX, centerY, 0);
309308
}
310309

311310
private void transition(int dZoom) {
@@ -371,14 +370,6 @@ public Vector2 geoInPixels(GeoPosition pos) {
371370
return new Vector2((float) ((point.x / mapW) * Math.pow(2, zoom)), (float) ((point.y / mapH) * Math.pow(2, zoom)));
372371
}
373372

374-
// Only register clicks within map bounds
375-
public void click(float screenX, float screenY) {
376-
Vector3 vector3 = new Vector3(screenX, screenY, 0);
377-
camera.unproject(vector3);
378-
System.out.println(vector3);
379-
zoom(2 * vector3.x, 2 * vector3.y, 1);
380-
}
381-
382373
public TextureRegion getMapTexture() {
383374
return mapRegion;
384375
}

0 commit comments

Comments
 (0)