Skip to content

Commit

Permalink
Static Map Background
Browse files Browse the repository at this point in the history
  • Loading branch information
Moksh-Mehta7 committed Sep 5, 2023
1 parent 05b5467 commit 97a2bc2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
Binary file added source/core/assets/images/ingamebg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public class ForestGameArea extends GameArea {

// Required to load assets before using them
private static final String[] forestTextures = {
"images/ingamebg.png",
"images/projectiles/projectile.png",
"images/box_boy_leaf.png",
"images/background/building1.png",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.badlogic.gdx.maps.tiled.TiledMapTileLayer;
import com.badlogic.gdx.maps.tiled.TiledMapTileLayer.Cell;
import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer;
import com.badlogic.gdx.maps.tiled.tiles.StaticTiledMapTile;
import com.badlogic.gdx.math.GridPoint2;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
Expand Down Expand Up @@ -98,19 +99,34 @@ private TiledMapRenderer createRenderer(TiledMap tiledMap, float tileScale) {
}
}

private TiledMap createForestDemoTiles(
GridPoint2 tileSize, TextureRegion grass) {
private TiledMap createForestDemoTiles(GridPoint2 tileSize, TextureRegion grass) {
TiledMap tiledMap = new TiledMap();
TerrainTile grassTile = new TerrainTile(grass);
TiledMapTileLayer layer = new TiledMapTileLayer(MAP_SIZE.x, MAP_SIZE.y, tileSize.x, tileSize.y);

// Create base grass
fillTiles(layer, MAP_SIZE, grassTile);
// Create a background layer
TiledMapTileLayer backgroundLayer = new TiledMapTileLayer(20, 8, tileSize.x, tileSize.y);
TextureRegion backgroundTextureRegion = new TextureRegion(ServiceLocator.getResourceService().getAsset("images/ingamebg.png", Texture.class));

// Create a single cell for the entire background image
Cell cell = new Cell();
cell.setTile(new StaticTiledMapTile(backgroundTextureRegion));
backgroundLayer.setCell(0, 0, cell);

tiledMap.getLayers().add(backgroundLayer);

// Create a grass layer
TerrainTile grassTile = new TerrainTile(grass);
TiledMapTileLayer grassLayer = new TiledMapTileLayer(20, 8, tileSize.x, tileSize.y);
fillTiles(grassLayer, new GridPoint2(20, 8), grassTile);
tiledMap.getLayers().add(grassLayer);

tiledMap.getLayers().add(layer);
return tiledMap;
}






private static void fillTiles(TiledMapTileLayer layer, GridPoint2 mapSize, TerrainTile tile) {
BitmapFont font = new BitmapFont();
TextButton.TextButtonStyle textButtonStyle = new TextButton.TextButtonStyle();
Expand Down

0 comments on commit 97a2bc2

Please sign in to comment.