List of usage examples for com.badlogic.gdx.maps.tiled.renderers OrthogonalTiledMapRenderer OrthogonalTiledMapRenderer
public OrthogonalTiledMapRenderer(TiledMap map, float unitScale, Batch batch)
From source file:ca.hiphiparray.amazingmaze.MazeScreen.java
License:Open Source License
/** * Constructor for the maze screen./*from ww w . j a va 2 s . co m*/ * * @param game the {@link AmazingMazeGame} instance that is managing this screen. * @param help if this is the tutorial level. */ public MazeScreen(final AmazingMazeGame game, boolean help) { final int mapSize = 2; this.game = game; this.paused = false; this.help = help; this.mapWidth = 16 * mapSize + game.save.getLevel() * 5; this.mapHeight = 9 * mapSize; camera = new OrthographicCamera(); camera.setToOrtho(false, 16 * mapSize, this.mapHeight); viewport = new ExtendViewport(0, this.mapHeight, this.mapWidth, this.mapHeight, camera); MapFactory factory; if (!help) { factory = new MapFactory(game, game.save.getLevel(), this.mapWidth, this.mapHeight, TILE_SIZE); } else { this.mapHeight = this.mapHeight * 5 / 8; factory = new MapFactory(game, -3, this.mapWidth, this.mapHeight, TILE_SIZE); } map = factory.generateMap(); gateLocations = factory.getGateLocations(); gateOn = factory.getGateOn(); createBoundingBoxes(); mapRenderer = new OrthogonalTiledMapRenderer(map, MAP_SCALE, game.batch); player = new Player(game.assets.manager.get(Assets.GAME_ATLAS_LOCATION, TextureAtlas.class) .findRegion(Assets.PLACEHOLDER), this); player.setScale(MAP_SCALE); if (!help) { setupHUD(); } setupPauseMenu(); input = new InputMultiplexer(pauseMenu, this); }
From source file:com.agateau.pixelwheels.racescreen.GameRenderer.java
License:Open Source License
public GameRenderer(GameWorld world, Batch batch, PerformanceCounters counters) { mDebugRenderer = new Box2DDebugRenderer(); mWorld = world;/*from ww w. j a v a 2 s. c o m*/ mTrack = mWorld.getTrack(); mExtraBackgroundLayerIndexes = mTrack.getExtraBackgroundLayerIndexes(); mForegroundLayerIndexes = mTrack.getForegroundLayerIndexes(); mBatch = batch; mCamera = new OrthographicCamera(); boolean singlePlayer = mWorld.getPlayerRacers().size == 1; mCameraUpdater = singlePlayer ? new SinglePlayerCameraUpdater(mWorld) : new MultiPlayerCameraUpdater(mWorld); mRenderer = new OrthogonalTiledMapRenderer(mTrack.getMap(), Constants.UNIT_FOR_PIXEL, mBatch); mTilePerformanceCounter = counters.add("- tiles"); mGameObjectPerformanceCounter = counters.add("- g.o."); mDebugRenderer.setDrawVelocities(Debug.instance.drawVelocities); }
From source file:com.redtoorange.game.components.rendering.sprite.MapRenderComponent.java
License:Open Source License
/** * @param map TiledMap loaded from a file on disk and rendered by this component. * @param mapScale Amount to scale the map to fit correctly with the world units. * @param batch The batch that this map will used to render. * @param camera The camera that is following the player. *//*from w w w. ja va 2 s .co m*/ public MapRenderComponent(TiledMap map, float mapScale, SpriteBatch batch, OrthographicCamera camera) { this.camera = camera; mapRenderer = new OrthogonalTiledMapRenderer(map, mapScale, batch); }
From source file:headmade.arttag.utils.MapUtils.java
License:Apache License
public static void loadMap(ArtTagScreen artTagScreen, String mapName) { if (artTagScreen.currentRoom != null) { unloadMap(artTagScreen);//from www . j a va2 s . c o m } if (null != Player.instance.warpDirection) { Gdx.app.log(TAG, "Loading map " + mapName); if (DIRECTION_LEFT.equalsIgnoreCase(Player.instance.warpDirection)) { if (artTagScreen.currentRoomIndexX == 0) { artTagScreen.currentRoomIndexX = ArtTagScreen.MAX_ROOM_SIZE - 1; } else { artTagScreen.currentRoomIndexX--; } } else if (DIRECTION_RIGHT.equalsIgnoreCase(Player.instance.warpDirection)) { if (artTagScreen.currentRoomIndexX == ArtTagScreen.MAX_ROOM_SIZE - 1) { artTagScreen.currentRoomIndexX = 0; } else { artTagScreen.currentRoomIndexX++; } } else if (DIRECTION_TOP.equalsIgnoreCase(Player.instance.warpDirection)) { if (artTagScreen.currentRoomIndexY == ArtTagScreen.MAX_ROOM_SIZE - 1) { artTagScreen.currentRoomIndexY = 0; } else { artTagScreen.currentRoomIndexY++; } } else if (DIRECTION_BOTTOM.equalsIgnoreCase(Player.instance.warpDirection)) { if (artTagScreen.currentRoomIndexY == 0) { artTagScreen.currentRoomIndexY = ArtTagScreen.MAX_ROOM_SIZE - 1; } else { artTagScreen.currentRoomIndexY--; } } } boolean isNewRoom = true; if (artTagScreen.rooms[artTagScreen.currentRoomIndexX][artTagScreen.currentRoomIndexY] == null) { artTagScreen.currentRoom = new Room(mapName); artTagScreen.rooms[artTagScreen.currentRoomIndexX][artTagScreen.currentRoomIndexY] = artTagScreen.currentRoom; } else { artTagScreen.currentRoom = artTagScreen.rooms[artTagScreen.currentRoomIndexX][artTagScreen.currentRoomIndexY]; isNewRoom = false; } final Box2DMapObjectParser parser = new Box2DMapObjectParser(ArtTag.UNIT_SCALE); // final Box2DMapObjectParser.Listener.Adapter listener = new Box2DMapObjectParser.Listener.Adapter() { // // @Override // public void created(Fixture fixture, MapObject mapObject) { // // Gdx.app.log(TAG, "mapObject.getProperties()" + fixture.getFilterData().maskBits); // super.created(fixture, mapObject); // } // // }; // parser.setListener(listener); final TiledMap map = artTagScreen.currentRoom.getMap(); final String onGameOver = map.getProperties().get(PROP_ONGAMEOVER, String.class); final String hideJobDesc = map.getProperties().get(PROP_ONGAMEOVER, String.class); artTagScreen.onGameOver = onGameOver; artTagScreen.isHideJobDesc = hideJobDesc == null ? false : true; parser.load(artTagScreen.world, map); if (null == artTagScreen.mapRenderer) { // artTagScreen.mapRenderer = new OrthogonalTiledMapRenderer(artTagScreen.map, artTagScreen.getGame().getBatch()); artTagScreen.mapRenderer = new OrthogonalTiledMapRenderer(map, parser.getUnitScale(), artTagScreen.getGame().getBatch()); } else { artTagScreen.mapRenderer.setMap(map); } MapLayer layer = map.getLayers().get("objects"); for (final MapObject mapObject : layer.getObjects()) { if (OBJ_ART.equals(mapObject.getName())) { if (isNewRoom) { // add Art only if this a new room. If this is an old room the art was created before. if (mapObject instanceof RectangleMapObject) { createNewArt(artTagScreen, mapObject, ((RectangleMapObject) mapObject).getRectangle(), parser.getUnitScale()); } else { Gdx.app.error(TAG, OBJ_ART + " has to be a Rectangle"); } } } else if (OBJ_WARP.equals(mapObject.getName())) { final Body warp = createWarp(artTagScreen, ((RectangleMapObject) mapObject).getRectangle(), parser.getUnitScale()); final String direction = mapObject.getProperties().get(PROP_DIRECTION, String.class); final String room = mapObject.getProperties().get(PROP_ROOM, String.class); warp.setUserData(new WarpVo(direction, room)); } else if (OBJ_EXIT.equals(mapObject.getName())) { createExit(artTagScreen, ((RectangleMapObject) mapObject).getRectangle(), parser.getUnitScale()); } else if (OBJ_HINT.equals(mapObject.getName())) { final Body hintBody = createHint(artTagScreen, ((RectangleMapObject) mapObject).getRectangle(), parser.getUnitScale()); final String hint = mapObject.getProperties().get(PROP_TEXT, String.class); hintBody.setUserData(hint); } else if (OBJ_PLAYER.equals(mapObject.getName())) { final Ellipse e = ((EllipseMapObject) mapObject).getEllipse(); if (null == Player.instance.body) { final String direction = mapObject.getProperties().get("direction", String.class); if (null != Player.instance.warpDirection) { if (Player.instance.warpDirection.equalsIgnoreCase(direction)) { Player.instance.createBody(artTagScreen, (e.x + e.width / 2f) * parser.getUnitScale(), (e.y + e.height / 2f) * parser.getUnitScale()); Player.instance.warpDirection = null; } } else if (direction == null) { Player.instance.createBody(artTagScreen, (e.x + e.width / 2f) * parser.getUnitScale(), (e.y + e.height / 2f) * parser.getUnitScale()); } } } } if (!isNewRoom) { // create ArtSensors for old Art for (final Art art : artTagScreen.currentRoom.getArtList()) { createArtSensor(artTagScreen, art); } } { // guards final HashMap<String, Guard> guards = new HashMap<String, Guard>(); final Array<MapObject> paths = new Array<MapObject>(); layer = map.getLayers().get("guards"); for (final MapObject mapObject : layer.getObjects()) { if (mapObject.getName() != null && mapObject.getName().contains(OBJ_GUARD)) { final Ellipse e = ((EllipseMapObject) mapObject).getEllipse(); final Guard g = new Guard(); g.createBody(artTagScreen, (e.x + e.width / 2f) * parser.getUnitScale(), (e.y + e.height / 2f) * parser.getUnitScale()); guards.put(mapObject.getName().trim(), g); } else if (mapObject.getName() != null && mapObject.getName().contains(OBJ_PATH)) { paths.add(mapObject); } else { Gdx.app.log(TAG, "WTF"); } } for (final MapObject mapObject : paths) { final PolylineMapObject pl = (PolylineMapObject) mapObject; final String ownerName = pl.getProperties().get("owner", String.class); final Guard g = guards.get(ownerName.trim()); Gdx.app.log(TAG, "guards " + guards.keySet()); if (g != null) { final Polyline orgPolyline = pl.getPolyline(); final Polyline p = new Polyline(orgPolyline.getVertices()); p.setScale(parser.getUnitScale(), parser.getUnitScale()); p.setPosition(orgPolyline.getX() * parser.getUnitScale(), orgPolyline.getY() * parser.getUnitScale()); final float[] vertices = p.getTransformedVertices(); for (int i = 0; i < vertices.length; i += 2) { g.path.add(new Vector2(vertices[i], vertices[i + 1])); } artTagScreen.guards.add(g); } else { Gdx.app.log(TAG, "No guard for path " + ownerName); } } } layer = map.getLayers().get("lights"); for (final MapObject mapObject : layer.getObjects()) { if (mapObject.getProperties().get("type", String.class).contains(LIGTH_POINT)) { if (mapObject instanceof EllipseMapObject) { createPointLight(artTagScreen, (EllipseMapObject) mapObject, parser.getUnitScale()); } else { Gdx.app.error(TAG, LIGTH_POINT + " light has to be a Circle not " + mapObject); } } else if (mapObject.getProperties().get("type", String.class).contains(LIGTH_CONE)) { if (mapObject instanceof PolygonMapObject) { createConeLight(artTagScreen, (PolygonMapObject) mapObject, parser.getUnitScale()); } else { Gdx.app.error(TAG, LIGTH_CONE + " light has to be a Polygon"); } } } }
From source file:org.lightjason.examples.pokemon.ui.CScreen.java
License:LGPL
@Override public final void create() { // create orthogonal camera perspective final float l_unit = 1.0f / m_environment.cellsize(); // create execution structure for painting m_spritebatch = new SpriteBatch(); // create environment view and put all objects in it m_render = new OrthogonalTiledMapRenderer(m_environment.map(), l_unit, m_spritebatch); m_camera = new OrthographicCamera(m_environment.column(), m_environment.row()); m_camera.setToOrtho(false, m_environment.column() * l_unit, m_environment.row() * l_unit); m_camera.position.set(m_environment.column() / 2f, m_environment.row() / 2f, 0); m_camera.zoom = m_environment.cellsize(); // create sprites and particle systems m_sprites.forEach(i -> i.spriteinitialize(m_environment.row(), m_environment.column(), m_environment.cellsize(), l_unit)); m_render.setView(m_camera);/*from w ww . ja va2 s. c o m*/ // set input processor Gdx.input.setInputProcessor(this); }