C
- The collision type used.T
- The tile type used.public abstract class MapTileGame<C extends java.lang.Enum<C>,T extends TileGame<C>> extends java.lang.Object implements MapTile<C,T>
The way to prepare a map is the following:
A simple call tocreate(int, int)
// prepare memory to store tilesloadPatterns(Media)
// load tilesheet
load(FileReading)
will automatically perform theses operations.TileGame
Modifier and Type | Field and Description |
---|---|
static int |
BLOC_SIZE
Number of horizontal tiles to make a bloc.
|
Constructor and Description |
---|
MapTileGame(int tileWidth,
int tileHeight)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
append(MapTile<C,T> map,
int offsetX,
int offsetY)
Append an existing map, starting at the specified offsets.
|
void |
clear()
Remove all tiles from map.
|
void |
create(int widthInTile,
int heightInTile)
Create and prepare map memory area.
|
void |
createMiniMap()
Generate the minimap from the current map.
|
abstract T |
createTile(int width,
int height,
java.lang.Integer pattern,
int number,
C collision)
Create a tile.
|
abstract C |
getCollisionFrom(java.lang.String collision)
Get collision type from its name as string.
|
int |
getHeightInTile()
Get number of vertical tiles.
|
com.b3dgs.lionengine.core.ImageBuffer |
getMiniMap()
Get minimap surface reference.
|
int |
getNumberPatterns()
Get the number of used pattern.
|
int |
getNumberTiles()
Get number of active tiles (which are not
null ). |
com.b3dgs.lionengine.drawable.SpriteTiled |
getPattern(java.lang.Integer pattern)
Get pattern (tilesheet) from its id.
|
java.util.Set<java.lang.Integer> |
getPatterns()
Get list of patterns id.
|
com.b3dgs.lionengine.core.Media |
getPatternsDirectory()
Get map theme.
|
T |
getTile(int tx,
int ty)
Get tile from specified map location (in tile index).
|
int |
getTileHeight()
Get height of a tile.
|
int |
getTileWidth()
Get width of a tile.
|
int |
getWidthInTile()
Get number of horizontal tiles.
|
void |
load(com.b3dgs.lionengine.file.FileReading file)
Load a map from a specified file as binary data.
|
void |
loadCollisions(com.b3dgs.lionengine.core.Media media)
Load map collision from an external file.
|
void |
loadPatterns(com.b3dgs.lionengine.core.Media directory)
Load map patterns (tiles surfaces) from theme name.
|
T |
loadTile(java.util.List<com.b3dgs.lionengine.file.XmlNode> nodes,
com.b3dgs.lionengine.file.FileReading file,
int i)
Load tile.
|
void |
render(com.b3dgs.lionengine.Graphic g,
CameraGame camera)
Render map from camera viewpoint, showing a specified area.
|
void |
renderMiniMap(com.b3dgs.lionengine.Graphic g,
int x,
int y)
Render minimap on graphic output at specified location.
|
void |
save(com.b3dgs.lionengine.file.FileWriting file)
Save map to specified file as binary data.
|
void |
setTile(int v,
int h,
T tile)
Set a tile at specified map indexes.
|
public static final int BLOC_SIZE
public MapTileGame(int tileWidth, int tileHeight)
tileWidth
- The tile width.tileHeight
- The tile height.public abstract T createTile(int width, int height, java.lang.Integer pattern, int number, C collision)
width
- The tile width.height
- The tile height.pattern
- The tile pattern.number
- The tile number.collision
- The tile collision.public abstract C getCollisionFrom(java.lang.String collision)
collision
- The collision name.public void createMiniMap()
public void save(com.b3dgs.lionengine.file.FileWriting file) throws java.io.IOException
Collisions are not saved, because it is possible to retrieve them from collisions.txt(String)
theme(short)
width in tiles(short)
height in tiles(byte)
tile width (use of byte because tile width < 255)(byte)
tile height (use of byte because tile height < 255)(short)
number of 256 horizontal blocs (widthInTile / 256) for each blocs tile(short)
number of tiles in this bloc for each tile in this bloc call tile.save(file)
file
- The output file.java.io.IOException
- If error on writing.public void load(com.b3dgs.lionengine.file.FileReading file) throws java.io.IOException
Data are loaded this way (see save(file) order):
(String)
theme(short)
width in tiles(short)
height in tiles(byte)
tile width(byte)
tile height(short)
number of 256 horizontal blocs (widthInTile / 256) for each blocs tile(short)
number of tiles in this bloc for each tile in this bloc create blank tile call tile.load(file) call this.setTile(...) to update map with this new tile
file
- The input file.java.io.IOException
- If error on reading.public void loadCollisions(com.b3dgs.lionengine.core.Media media)
media
- The collision container.public T loadTile(java.util.List<com.b3dgs.lionengine.file.XmlNode> nodes, com.b3dgs.lionengine.file.FileReading file, int i) throws java.io.IOException
(integer) pattern number (integer) index number inside pattern (integer) tile location x (integer tile location y
nodes
- The collision nodes.file
- The file reader reference.i
- The last loaded tile number.java.io.IOException
- If error on reading.public void renderMiniMap(com.b3dgs.lionengine.Graphic g, int x, int y)
g
- The graphic output.x
- The location x.y
- The location y.public void setTile(int v, int h, T tile)
v
- The vertical index.h
- The horizontal index.tile
- The tile reference.public com.b3dgs.lionengine.drawable.SpriteTiled getPattern(java.lang.Integer pattern)
pattern
- The pattern id.public java.util.Set<java.lang.Integer> getPatterns()
public com.b3dgs.lionengine.core.Media getPatternsDirectory()
public com.b3dgs.lionengine.core.ImageBuffer getMiniMap()
public void create(int widthInTile, int heightInTile)
MapTile
public void append(MapTile<C,T> map, int offsetX, int offsetY)
MapTile
MapTile.append(MapTile, int, int)
at (MapTile.getWidthInTile()
, MapTile.getHeightInTile()
) will add
the new map at the top-right.public void clear()
MapTile
public void loadPatterns(com.b3dgs.lionengine.core.Media directory)
MapTile
Collisions are stored this way: #NAME# = {pattern|firstTile-lastTile}, and called with: getCollision(name).
Patterns number and name have to be written inside a file named 'count', else, all files as .png will be loaded.
public void render(com.b3dgs.lionengine.Graphic g, CameraGame camera)
MapTile
public T getTile(int tx, int ty)
MapTile
null
, this
means that there is not tile at this location. It is not an error, just a way to avoid useless tile storage.public int getNumberPatterns()
MapTile
public int getNumberTiles()
MapTile
null
).public int getTileWidth()
MapTile
public int getTileHeight()
MapTile
public int getWidthInTile()
MapTile