#include <PhTileMap.h>
Public Member Functions | |
PhTileMap (PhSceneManager *sc, PhVector2d s, PhVector2d ts, PhTexture *t, float d=-100.0f) | |
Construct. | |
virtual | ~PhTileMap () |
Destruct. | |
void | setTile (int x, int t) |
Set tile. | |
void | setTile (PhVector2d pos, int t) |
Set tile. | |
int | getTile (int x) |
Get tile. | |
int | getTile (PhVector2d pos) |
Get tile. | |
void | setMapSize (PhVector2d s) |
Set map size. | |
PhVector2d | getMapSize () |
Get map size. | |
void | setTileSize (PhVector2d s) |
Set tile size. | |
PhVector2d | getTileSize () |
Get tile size. | |
void | setTexture (PhTexture *t) |
Set texture. | |
PhTexture * | getTexture () |
Get texture. | |
void | saveMap (string f) |
Save map. | |
void | loadMap (string f) |
Load map. | |
void | onRender () |
Render call. | |
void | onPreRender () |
Pre-render call. | |
void | onPostRender () |
Post-render call. | |
Protected Member Functions | |
void | allocateTiles () |
Allocates the map vector. | |
Protected Attributes | |
vector< int > | map |
Stores the values of the tiles. | |
PhVector2d | tilesize |
Stores the size of each tile (in pixels). | |
PhVector2d | tilemapsize |
Stores the size of the map itself (in tiles). | |
PhTexture * | texture |
Texture that is used to peice together the map. | |
PhSceneManager * | smgr |
Pointer to the scene manager. |
A simple yet highly effective tilemap scene node. Once it is created it's self-contained. The scene manager takes care of rendering it, all you really have to do is create the map and load it.
phoenix::PhTileMap::PhTileMap | ( | PhSceneManager * | sc, | |
PhVector2d | s, | |||
PhVector2d | ts, | |||
PhTexture * | t, | |||
float | d = -100.0f | |||
) |
Construct.
Builds a tilemap scene node.
sc | Pointer to the scene manager. | |
s | Size of the tilemap (in tiles). | |
ts | Size of each tile in the tilemap (in pixels). | |
t | Texture where the tiles will come from. | |
d | Depth of the tile map (default -100.0f). |
void phoenix::PhTileMap::setTile | ( | int | x, | |
int | t | |||
) |
Set tile.
Sets the tile at the given index to the given value.
x | Index of the tile. | |
t | New value of the tile. |
void phoenix::PhTileMap::setTile | ( | PhVector2d | pos, | |
int | t | |||
) |
Set tile.
Sets the tile at the given position to the given value.
pos | The position of the tile, ie <2,2> is the second tile from the top, second tile from the left. | |
t | The new value of the tile. |
int phoenix::PhTileMap::getTile | ( | int | x | ) |
Get tile.
x | Index of the tile. |
int phoenix::PhTileMap::getTile | ( | PhVector2d | pos | ) |
Get tile.
pos | Position of the tile. |
void phoenix::PhTileMap::setMapSize | ( | PhVector2d | s | ) |
PhVector2d phoenix::PhTileMap::getMapSize | ( | ) |
void phoenix::PhTileMap::setTileSize | ( | PhVector2d | s | ) |
PhVector2d phoenix::PhTileMap::getTileSize | ( | ) |
void phoenix::PhTileMap::setTexture | ( | PhTexture * | t | ) |
PhTexture* phoenix::PhTileMap::getTexture | ( | ) |
void phoenix::PhTileMap::saveMap | ( | string | f | ) |
Save map.
Saves the current tilemap to a file.
File format information:
first four bytes are the x of the mapsize.
second four bytes are the y of the mapsize.
third set of bytes is the x of the tilesize.
fourth set of bytes is the y of the tilesize.
remaining bytes each contain one tile.
f | Filename to save it to. |
void phoenix::PhTileMap::loadMap | ( | string | f | ) |
void phoenix::PhTileMap::onRender | ( | ) | [virtual] |
Render call.
Any nodes that called phoenix::PhSceneManger::registerForRendering() will first be sorted according to their depth, then this function is called for each node in order. It is highly suggested that you put any drawing code in this function. Of course, it's possible to draw during any of the three node passes, but this pass is the only one that is exclusive (Nodes must register) and is the only one that is depth sorted.
Reimplemented from phoenix::PhSceneNode.
void phoenix::PhTileMap::onPreRender | ( | ) | [virtual] |
Pre-render call.
All nodes in the list will have this function called by the scenemanger once per frame. Overloading this is required. If the scene node wants to be drawn it must call phoenix::PhSceneManger::registerForRendering().
Reimplemented from phoenix::PhSceneNode.
void phoenix::PhTileMap::onPostRender | ( | ) | [inline, virtual] |
Post-render call.
The third render pass takes place at the end of every frame, the scene manager calls this function for every node in the list, and any code that should happen after everything is drawn should go here.
Reimplemented from phoenix::PhSceneNode.