|
1 | 1 | package no.mehl.libgdx.map.example;
|
2 | 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.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; |
21 | 5 |
|
22 |
| -public class MapTest implements ApplicationListener, GestureDetector.GestureListener { |
| 6 | +public class MapTest { |
23 | 7 |
|
24 |
| - private Logger logger = new Logger(MapTest.class.getSimpleName(), Logger.INFO); |
| 8 | + public static void main(String[] args) { |
25 | 9 |
|
26 |
| - OrthographicCamera camera; |
27 |
| - private MapManager mapManager; |
| 10 | + LwjglApplicationConfiguration cfg = new LwjglApplicationConfiguration(); |
| 11 | + cfg.title = "uniquegameidentifaction"; |
| 12 | + cfg.width = 568; |
| 13 | + cfg.height = 1080; |
28 | 14 |
|
29 |
| - private Texture pin; |
30 |
| - private SpriteBatch batch; |
31 |
| - private Vector3 pinPos = new Vector3(); |
32 | 15 |
|
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); |
157 | 17 | }
|
158 | 18 | }
|
0 commit comments