Home | History | Annotate | Download | only in tests
      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.graphics.GL20;
     21 import com.badlogic.gdx.graphics.OrthographicCamera;
     22 import com.badlogic.gdx.graphics.g2d.BitmapFont;
     23 import com.badlogic.gdx.graphics.g2d.SpriteBatch;
     24 import com.badlogic.gdx.maps.tiled.TideMapLoader;
     25 import com.badlogic.gdx.maps.tiled.TiledMap;
     26 import com.badlogic.gdx.maps.tiled.TiledMapRenderer;
     27 import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer;
     28 import com.badlogic.gdx.tests.utils.GdxTest;
     29 import com.badlogic.gdx.tests.utils.OrthoCamController;
     30 
     31 public class TideMapDirectLoaderTest extends GdxTest {
     32 
     33 	private TiledMap map;
     34 	private TiledMapRenderer renderer;
     35 	private OrthographicCamera camera;
     36 	private OrthoCamController cameraController;
     37 	private BitmapFont font;
     38 	private SpriteBatch batch;
     39 
     40 	@Override
     41 	public void create () {
     42 		float w = Gdx.graphics.getWidth();
     43 		float h = Gdx.graphics.getHeight();
     44 
     45 		camera = new OrthographicCamera();
     46 		camera.setToOrtho(false, (w / h) * 10, 10);
     47 		camera.update();
     48 
     49 		cameraController = new OrthoCamController(camera);
     50 		Gdx.input.setInputProcessor(cameraController);
     51 
     52 		font = new BitmapFont();
     53 		batch = new SpriteBatch();
     54 
     55 		map = new TideMapLoader().load("data/maps/tide/Map01.tide");
     56 		renderer = new OrthogonalTiledMapRenderer(map, 1f / 32f);
     57 	}
     58 
     59 	@Override
     60 	public void render () {
     61 		Gdx.gl.glClearColor(0.55f, 0.55f, 0.55f, 1f);
     62 		Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
     63 		camera.update();
     64 		renderer.setView(camera);
     65 		renderer.render();
     66 		batch.begin();
     67 		font.draw(batch, "FPS: " + Gdx.graphics.getFramesPerSecond(), 10, 20);
     68 		batch.end();
     69 	}
     70 
     71 	@Override
     72 	public void dispose () {
     73 		map.dispose();
     74 	}
     75 }
     76