com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer Java Examples

The following examples show how to use com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BattleScreen.java    From Norii with Apache License 2.0 6 votes vote down vote up
@Override
public void show() {
	resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
	mapMgr.getCurrentTiledMap();

	multiplexer.addProcessor(currentMap.getTiledMapStage());
	Gdx.input.setInputProcessor(multiplexer);

	setupViewport(VISIBLE_WIDTH, VISIBLE_HEIGHT);
	mapCamera.position.set(currentMap.getMapWidth() / 2f, currentMap.getMapHeight() / 2f, 0f);
	mapRenderer = new OrthogonalTiledMapRenderer(mapMgr.getCurrentTiledMap(), Map.UNIT_SCALE);
	mapRenderer.setView(mapCamera);
	currentMap.makeSpawnParticles();

	final StretchViewport vp = new StretchViewport(VISIBLE_WIDTH, VISIBLE_HEIGHT, mapCamera);
	currentMap.getTiledMapStage().setViewport(vp);
	Player.getInstance().getEntityStage().setViewport(vp);
	aiTeam.getEntityStage().setViewport(vp);
}
 
Example #2
Source File: TiledRendererSystem.java    From Entitas-Java with MIT License 5 votes vote down vote up
@Override
public void initialize() {
    this.cam = context.getCamera().camera;
    Tiled tiled = context.getTiled();
    TiledMap tiledMap = assetsManager.getMap(tiled.tileMapName);
    this.tiledRenderer = new OrthogonalTiledMapRenderer(tiledMap, tiled.unitScale);

}
 
Example #3
Source File: WorldRenderer.java    From killingspree with MIT License 5 votes vote down vote up
public void loadLevel(String level, boolean isServer, String name) {
    this.isServer = isServer;
    map = new TmxMapLoader().load(level);
    TiledMapTileLayer layer = (TiledMapTileLayer) map.
                                getLayers().get("terrain");
    VIEWPORT_WIDTH = (int) (layer.getTileWidth() * layer.getWidth());
    VIEWPORT_HEIGHT = (int) (layer.getTileHeight() * layer.getHeight());
    viewport = new FitViewport(VIEWPORT_WIDTH, VIEWPORT_HEIGHT, camera);
    renderer = new OrthogonalTiledMapRenderer(map);
    name = name.trim();
    if (name.length() == 0)
        name = "noname";
    if (name.length() >= 10){
        name = name.substring(0, 10);
    }
    ClientDetailsMessage clientDetails = new ClientDetailsMessage();
    clientDetails.name = name;
    clientDetails.protocolVersion = Constants.PROTOCOL_VERSION;
    if (isServer) {
        MapLayer collision =  map.
                getLayers().get("collision");
        for(MapObject object: collision.getObjects()) {
            worldManager.createWorldObject(object);
        }
        worldManager.addIncomingEvent(MessageObjectPool.instance.
                eventPool.obtain().set(State.RECEIVED, clientDetails));
    } else {
        client.sendTCP(clientDetails);
    }
    controls = new onScreenControls();
    
}
 
Example #4
Source File: PlayScreen.java    From Pacman_libGdx with MIT License 4 votes vote down vote up
@Override
public void show() {
    camera = new OrthographicCamera();
    viewport = new FitViewport(WIDTH, HEIGHT, camera);
    camera.translate(WIDTH / 2, HEIGHT / 2);
    camera.update();

    batch = new SpriteBatch();

    playerSystem = new PlayerSystem();
    ghostSystem = new GhostSystem();
    movementSystem = new MovementSystem();
    pillSystem = new PillSystem();
    animationSystem = new AnimationSystem();
    renderSystem = new RenderSystem(batch);
    stateSystem = new StateSystem();

    engine = new Engine();
    engine.addSystem(playerSystem);
    engine.addSystem(ghostSystem);
    engine.addSystem(pillSystem);
    engine.addSystem(movementSystem);
    engine.addSystem(stateSystem);
    engine.addSystem(animationSystem);
    engine.addSystem(renderSystem);

    // box2d
    world = new World(Vector2.Zero, true);
    world.setContactListener(new WorldContactListener());
    box2DDebugRenderer = new Box2DDebugRenderer();
    showBox2DDebuggerRenderer = false;

    // box2d light
    rayHandler = new RayHandler(world);
    rayHandler.setAmbientLight(ambientLight);

    // load map
    tiledMap = new TmxMapLoader().load("map/map.tmx");
    tiledMapRenderer = new OrthogonalTiledMapRenderer(tiledMap, 1 / 16f, batch);

    new WorldBuilder(tiledMap, engine, world, rayHandler).buildAll();

    stageViewport = new FitViewport(WIDTH * 20, HEIGHT * 20);
    stage = new Stage(stageViewport, batch);

    font = new BitmapFont(Gdx.files.internal("fonts/army_stencil.fnt"));
    Label.LabelStyle labelStyle = new Label.LabelStyle(font, Color.WHITE);

    Label scoreTextLabel = new Label("SCORE", labelStyle);
    scoreTextLabel.setPosition(WIDTH * 1, HEIGHT * 19);
    stage.addActor(scoreTextLabel);

    Label hightScoreTextLabel = new Label("High Score", labelStyle);
    hightScoreTextLabel.setPosition(WIDTH * 14, HEIGHT * 19);
    stage.addActor(hightScoreTextLabel);

    scoreLabel = new Label("0", labelStyle);
    scoreLabel.setPosition(WIDTH * 1.5f, HEIGHT * 18.2f);
    stage.addActor(scoreLabel);

    highScoreLabel = new Label("0", labelStyle);
    highScoreLabel.setPosition(WIDTH * 16.5f, HEIGHT * 18.2f);
    stage.addActor(highScoreLabel);

    gameOverLabel = new Label("              - Game Over -\n Press Enter to continue", labelStyle);
    gameOverLabel.setPosition(WIDTH * 4.3f, HEIGHT * 9f);
    gameOverLabel.setVisible(false);
    stage.addActor(gameOverLabel);

    TextureAtlas textureAtlas = GameManager.instance.assetManager.get("images/actors.pack", TextureAtlas.class);
    pacmanSprite = new Sprite(new TextureRegion(textureAtlas.findRegion("Pacman"), 16, 0, 16, 16));
    pacmanSprite.setBounds(8f, 21.5f, 16 / GameManager.PPM, 16 / GameManager.PPM);

    stringBuilder = new StringBuilder();

    changeScreen = false;
}
 
Example #5
Source File: Map.java    From RuinsOfRevenge with MIT License 4 votes vote down vote up
public Map(FileLocation loc, String mapfile, Physics physics) {
	TmxObjectsLoader objs = null;
	try {
		objs = new TmxObjectsLoader(new XmlReader().parse(loc.getFile(mapfile)));
	} catch (IOException e) {
		e.printStackTrace();
	}
	this.map = new TmxMapLoader(loc.getResolver()).load(mapfile);
	this.renderer = new OrthogonalTiledMapRenderer(map, 1f / objs.getTileWidth());

	fringeLayerIndex = computeEntityLayer();
	if (fringeLayerIndex == 999) {
		belowEntities = new int[map.getLayers().getCount()];
		aboveEntities = new int[0];
		fillCounting(0, belowEntities);
		fringeLayer = null;
	} else {
		belowEntities = new int[fringeLayerIndex];
		aboveEntities = new int[map.getLayers().getCount()-fringeLayerIndex-1];
		fillCounting(0, belowEntities);
		fillCounting(fringeLayerIndex+1, aboveEntities);
		MapLayer mapLayer = map.getLayers().get(fringeLayerIndex);
		if (mapLayer instanceof TiledMapTileLayer) {
			fringeLayer = new FringeLayer(map, (TiledMapTileLayer) mapLayer);
		} else {
			fringeLayer = null;
		}
	}

	if (physics != null) {
		for (TmxObjectsLoader.TmxObjectGroup group : objs.getObjectGroups()) {
			for (TmxObjectsLoader.TmxObject obj : group.objects) {
				if (!obj.name.equalsIgnoreCase("spawnpoint")) {
					objs.loadToPhysics(obj, physics);
				} else {
					spawnpoint.set(obj.x / objs.getTileWidth(), obj.y / objs.getTileHeight());
				}
			}
		}
	}
}