public void createL0Animation(Texture tileTexture, String tag){ //hardcoded grass texture region Tile = new Array<StaticTiledMapTile>(); Tile.add(new StaticTiledMapTile(new TextureRegion(tileTexture,0,0,32,32))); Tile.add(new StaticTiledMapTile(new TextureRegion(tileTexture,32,0,32,32))); Tile.add(new StaticTiledMapTile(new TextureRegion(tileTexture,64,0,32,32))); TiledMapTileLayer layer = (TiledMapTileLayer) map.getLayers().get(0); for(int x = 0; x < layer.getWidth();x++){ for(int y = 0; y < layer.getHeight();y++){ TiledMapTileLayer.Cell cell = layer.getCell(x,y); Object property = cell.getTile().getProperties().get(tag); if(property != null){ cell.setTile(new AnimatedTiledMapTile(1.5f,Tile)); } } } }
public void createL1SmallAnimation(Texture tileTexture, String tag){ //hardcoded grass texture region Tile = new Array<StaticTiledMapTile>(); Tile.add(new StaticTiledMapTile(new TextureRegion(tileTexture,0,0,32,32))); Tile.add(new StaticTiledMapTile(new TextureRegion(tileTexture,32,0,32,32))); Tile.add(new StaticTiledMapTile(new TextureRegion(tileTexture,64,0,32,32))); TiledMapTileLayer layer = (TiledMapTileLayer) map.getLayers().get(1); for(int x = 0; x < layer.getWidth();x++){ for(int y = 0; y < layer.getHeight();y++){ TiledMapTileLayer.Cell cell = layer.getCell(x,y); if(cell!=null && cell.getTile().getProperties().get(tag)!=null){ cell.setTile(new AnimatedTiledMapTile(1.5f,Tile)); } } } }
public void createL1LargeAnimation(Texture tileTexture, String tag){ //hardcoded grass texture region Tile = new Array<StaticTiledMapTile>(); Tile.add(new StaticTiledMapTile(new TextureRegion(tileTexture,0,0,64,64))); Tile.add(new StaticTiledMapTile(new TextureRegion(tileTexture,64,0,64,64))); Tile.add(new StaticTiledMapTile(new TextureRegion(tileTexture,128,0,64,64))); TiledMapTileLayer layer = (TiledMapTileLayer) map.getLayers().get(1); for(int x = 0; x < layer.getWidth();x++){ for(int y = 0; y < layer.getHeight();y++){ TiledMapTileLayer.Cell cell = layer.getCell(x,y); if(cell!=null && cell.getTile().getProperties().get(tag)!=null){ cell.setTile(new AnimatedTiledMapTile(1.5f,Tile)); } } } }
/** * Make the tiles containing 'animation' key animated. * @param layer */ private void animateTiles(TiledMapTileLayer layer) { for (int x = 1; x < layer.getWidth(); x++) { for (int y = 1; y < layer.getHeight(); y++) { Cell cell = layer.getCell(x, y); if(cell != null) { TiledMapTile oldTile = cell.getTile(); if(oldTile.getProperties().containsKey("animation")) { String animation = (String) oldTile.getProperties().get("animation"); float speed = 0.15f; if(oldTile.getProperties().containsKey("speed")) { speed = Float.parseFloat((String) oldTile.getProperties().get("speed")); } AnimatedTiledMapTile newTile = new AnimatedTiledMapTile(speed, Tiles.getAnimatedTile(animation)); newTile.getProperties().putAll(oldTile.getProperties()); cell.setTile(newTile); } } } } }
@Override public void render() { clear(); input.update(); AnimatedTiledMapTile.updateAnimationBaseTime(); float delta = Gdx.graphics.getDeltaTime(); if (current_gamestates.size > 0) current_gamestates.peek().act(delta); game_stage.draw(); }
private void renderMap(){ // mapRenderer.getBatch().enableBlending(); // mapRenderer.getBatch().setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA); mapRenderer.setView(worldController.camera); // mapRenderer.render(); AnimatedTiledMapTile.updateAnimationBaseTime(); mapRenderer.getBatch().begin(); //地面 TiledMapTileLayer groundMapLayer = (TiledMapTileLayer)worldController.mapMgr.getCurrentMap().getLayers().get(MapsManager.GROUND_LAYER); if( groundMapLayer != null){ mapRenderer.renderTileLayer(groundMapLayer); } TiledMapTileLayer floorMapLayer = (TiledMapTileLayer)worldController.mapMgr.getCurrentMap().getLayers().get(MapsManager.FLOOR_LAYER); if( floorMapLayer != null){ mapRenderer.renderTileLayer(floorMapLayer); } //blocks TiledMapTileLayer blockMapLayer = (TiledMapTileLayer)worldController.mapMgr.getCurrentMap().getLayers().get(MapsManager.BLOCK_LAYER); if( blockMapLayer != null && Gdx.app.getLogLevel()== Application.LOG_DEBUG){ mapRenderer.renderTileLayer(blockMapLayer); } mapRenderer.getBatch().end(); mapRenderer.getBatch().begin(); //aim if(worldController.aim !=null){ worldController.aim.draw(mapRenderer.getBatch()); } //show roles order by Y-axis List<Sprite> temp =new ArrayList<Sprite>(); temp.add(worldController.player); temp.addAll(worldController.mapMgr.npcs); temp.addAll(worldController.mapMgr.enemies); temp.addAll(worldController.mapMgr.traps); Collections.sort(temp, new Comparator<Sprite>() { @Override public int compare(Sprite lhs, Sprite rhs) { // -1 - less than, 1 - greater than, 0 - equal, all inversed for descending return lhs.getY() > rhs.getY() ? -1 : (lhs.getY() < rhs.getY() ) ? 1 : 0; } }); for (Sprite sprite : temp) { sprite.draw(mapRenderer.getBatch()); } //ceil layer TiledMapTileLayer ceilMapLayer = (TiledMapTileLayer)worldController.mapMgr.getCurrentMap().getLayers().get(MapsManager.CEILING_LAYER); if( ceilMapLayer != null){ mapRenderer.renderTileLayer(ceilMapLayer); } if(worldController.skill!=null)worldController.skill.draw(mapRenderer.getBatch()); //TODO Sky Layer mapRenderer.getBatch().end(); }
/** Called before the rendering of all layers starts. */ protected void beginRender () { AnimatedTiledMapTile.updateAnimationBaseTime(); batch.begin(); }