SHARE
TWEET

Untitled

a guest Oct 25th, 2015 119 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.mouse.game;
  2.  
  3. import com.badlogic.gdx.Gdx;
  4. import com.badlogic.gdx.Input;
  5. import com.badlogic.gdx.Screen;
  6. import com.badlogic.gdx.graphics.GL20;
  7. import com.badlogic.gdx.graphics.OrthographicCamera;
  8. import com.badlogic.gdx.maps.tiled.TiledMap;
  9. import com.badlogic.gdx.maps.tiled.TiledMapRenderer;
  10. import com.badlogic.gdx.maps.tiled.TmxMapLoader;
  11. import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer;
  12. import com.badlogic.gdx.math.Vector2;
  13. import com.badlogic.gdx.physics.box2d.*;
  14. import com.badlogic.gdx.utils.viewport.FitViewport;
  15. import com.badlogic.gdx.utils.viewport.ScreenViewport;
  16. import com.badlogic.gdx.utils.viewport.StretchViewport;
  17. import com.badlogic.gdx.utils.viewport.Viewport;
  18.  
  19.  
  20. public class PlayScreen implements Screen {
  21.  
  22.     private MouseGame game;
  23.     private OrthographicCamera cam;
  24.     private Viewport gameView;
  25.     private TiledMap map;
  26.     private OrthogonalTiledMapRenderer mapRenderer;
  27.  
  28.     public World world;
  29.  
  30.     public Box2DDebugRenderer debug;
  31.  
  32.     public PlayScreen(MouseGame game){
  33.         this.game = game;
  34.         cam = new OrthographicCamera();
  35.         gameView = new FitViewport(game.V_WIDTH, game.V_HEIGHT, cam);
  36.  
  37.  
  38.       //  world = new World(new Vector2(0, 0), true);
  39.  
  40.         map = new TmxMapLoader().load("TestMap2.tmx");
  41.         mapRenderer = new OrthogonalTiledMapRenderer(map, 16f);
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.         debug = new Box2DDebugRenderer();
  49.  
  50.         //BodyDef bdef = new BodyDef();
  51.        // PolygonShape shape = new PolygonShape();
  52.         //Fixture fdef = new FixtureDef();
  53.     }
  54.  
  55.     public void handleInput(float dt){
  56.  
  57.         if (Gdx.input.isKeyPressed(Input.Keys.D)) cam.position.x += 150;
  58.  
  59.     }
  60.  
  61.     public void update(float dt){
  62.         handleInput(dt);
  63.         cam.update();
  64.         cam.setToOrtho(false, gameView.getWorldWidth() / 2 , gameView.getWorldHeight() / 2);
  65.         mapRenderer.setView(cam);
  66.     }
  67.  
  68.     @Override
  69.     public void show() {
  70.  
  71.     }
  72.  
  73.     @Override
  74.     public void render(float delta) {
  75.         Gdx.gl.glClearColor(0, 0 ,0 ,1);
  76.         Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
  77.  
  78.         mapRenderer.render();
  79.         game.batch.setProjectionMatrix(cam.combined);
  80.  
  81.         System.out.println(mapRenderer.getViewBounds());
  82.  
  83.  
  84.  
  85.     }
  86.  
  87.     @Override
  88.     public void resize(int width, int height) {
  89.  
  90.  
  91.  
  92.     }
  93.  
  94.     @Override
  95.     public void pause() {
  96.  
  97.     }
  98.  
  99.     @Override
  100.     public void resume() {
  101.  
  102.     }
  103.  
  104.     @Override
  105.     public void hide() {
  106.  
  107.     }
  108.  
  109.     @Override
  110.     public void dispose() {
  111.         map.dispose();
  112.         mapRenderer.dispose();
  113.  
  114.  
  115.     }
  116. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top