Class Tile
- All Implemented Interfaces:
Cloneable
- Direct Known Subclasses:
EmptyTile,GroundTile
Tile class represents a single tile on the game board.
Each tile can hold a specific TileContent, which may be an item, a static object
like a wall, or any other entity that occupies a tile.
This class provides rendering functionality, allowing each tile to display its texture on the screen. The texture and content of each tile can be configured and updated, enabling dynamic changes on the game board.
As an abstract class, Tile can be extended to create specific types of tiles
with unique behaviors or additional properties.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionTile(com.badlogic.gdx.graphics.Texture texture) Constructs a newTilewith the specified texture. -
Method Summary
Modifier and TypeMethodDescriptionclone()voiddispose()Releases the resources used by this tile.booleanRetrieves theTileContentcurrently placed on this tile.Removes and returns the topTileContentfrom this tile.voidpushTileContent(TileContent tileContent) Adds the specifiedTileContentto this tile.voidrender(com.badlogic.gdx.graphics.g2d.Batch batch, float x, float y) Renders the tile at the specified coordinates using the givenSpriteBatch.voidsetTileContent(TileContent tileContent) Sets theTileContentfor this tile.Retrieves the topTileContentfrom this tile without removing it.
-
Constructor Details
-
Tile
public Tile(com.badlogic.gdx.graphics.Texture texture) Constructs a newTilewith the specified texture.This constructor initializes the tile's texture and creates a corresponding
Sprite, setting its origin to the center. The texture is used for rendering the tile.- Parameters:
texture- theTextureto be used for this tile's appearance
-
-
Method Details
-
render
public void render(com.badlogic.gdx.graphics.g2d.Batch batch, float x, float y) Renders the tile at the specified coordinates using the givenSpriteBatch. If the tile has no texture, this method renders nothing.If the tile has a
TileContent, the render method of the content is called.- Parameters:
batch- theSpriteBatchused to render the tilex- the x-coordinate for rendering the tiley- the y-coordinate for rendering the tile
-
getTileContent
Retrieves theTileContentcurrently placed on this tile.- Returns:
- the current
TileContenton the tile, ornullif none is set
-
setTileContent
Sets theTileContentfor this tile.This method replaces any existing content on the tile with the specified
TileContent.- Parameters:
tileContent- the newTileContentto set on the tile
-
pushTileContent
Adds the specifiedTileContentto this tile.If the tile currently has no content, the provided
TileContentis set directly. Otherwise, the new content is pushed onto the existing content stack.- Parameters:
tileContent- theTileContentto add to the tile
-
popTileContent
Removes and returns the topTileContentfrom this tile.If the tile's content is a stack (i.e., contains nested
TileContent), this method removes and returns the top element of that stack. If there is only one content element, it is removed and the tile's content is set tonull. If the tile has no content,nullis returned.- Returns:
- the removed
TileContent, ornullif the tile was empty
-
topTileContent
Retrieves the topTileContentfrom this tile without removing it.If the tile's content is a stack of
TileContentobjects, this method returns the top element of that stack. If the tile has no content, it returnsnull.- Returns:
- the top
TileContenton the tile, ornullif the tile is empty
-
clone
-
equals
-
dispose
public void dispose()Releases the resources used by this tile.Disposes of the tile's texture if it is not
null, and also callsdispose()on itsTileContentif present.
-