• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*******************************************************************************
2  * Copyright 2011 See AUTHORS file.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  ******************************************************************************/
16 
17 package com.badlogic.gdx.tests;
18 
19 import com.badlogic.gdx.Gdx;
20 import com.badlogic.gdx.assets.AssetManager;
21 import com.badlogic.gdx.assets.loaders.resolvers.InternalFileHandleResolver;
22 import com.badlogic.gdx.graphics.GL20;
23 import com.badlogic.gdx.graphics.OrthographicCamera;
24 import com.badlogic.gdx.graphics.g2d.BitmapFont;
25 import com.badlogic.gdx.graphics.g2d.SpriteBatch;
26 import com.badlogic.gdx.maps.tiled.TideMapLoader;
27 import com.badlogic.gdx.maps.tiled.TiledMap;
28 import com.badlogic.gdx.maps.tiled.TiledMapRenderer;
29 import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer;
30 import com.badlogic.gdx.tests.utils.GdxTest;
31 import com.badlogic.gdx.tests.utils.OrthoCamController;
32 
33 public class TideMapAssetManagerTest extends GdxTest {
34 
35 	private TiledMap map;
36 	private TiledMapRenderer renderer;
37 	private OrthographicCamera camera;
38 	private OrthoCamController cameraController;
39 	private AssetManager assetManager;
40 	private BitmapFont font;
41 	private SpriteBatch batch;
42 
43 	@Override
create()44 	public void create () {
45 		float w = Gdx.graphics.getWidth();
46 		float h = Gdx.graphics.getHeight();
47 
48 		camera = new OrthographicCamera();
49 		camera.setToOrtho(false, (w / h) * 10, 10);
50 		camera.zoom = 2;
51 		camera.update();
52 
53 		cameraController = new OrthoCamController(camera);
54 		Gdx.input.setInputProcessor(cameraController);
55 
56 		font = new BitmapFont();
57 		batch = new SpriteBatch();
58 
59 		assetManager = new AssetManager();
60 		assetManager.setLoader(TiledMap.class, new TideMapLoader(new InternalFileHandleResolver()));
61 		assetManager.load("data/maps/tide/Map01.tide", TiledMap.class);
62 		assetManager.finishLoading();
63 		map = assetManager.get("data/maps/tide/Map01.tide");
64 		renderer = new OrthogonalTiledMapRenderer(map, 1f / 32f);
65 	}
66 
67 	@Override
render()68 	public void render () {
69 		Gdx.gl.glClearColor(0.55f, 0.55f, 0.55f, 1f);
70 		Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
71 		camera.update();
72 		renderer.setView(camera);
73 		renderer.render();
74 		batch.begin();
75 		font.draw(batch, "FPS: " + Gdx.graphics.getFramesPerSecond(), 10, 20);
76 		batch.end();
77 	}
78 }
79