Skip to content
This repository has been archived by the owner on Feb 19, 2018. It is now read-only.

Tileset

Andrés edited this page Feb 21, 2015 · 34 revisions

This Documentation is from a code still under heavy development, you may find errors,sudden changes or the answer to life,universe and everything

###Overview Tileset stores and defines a set of tiles with the same size to be used when drawing a map and checking tiles properties (tile_type), each map should have a pointer to a single tileset (different maps can point to the same tileset as long as the tiles ids are correct), with the tile_id is possible to access to that tile information through the Tileset. Each tile id in the tileset won't change until that tile is erased from the tileset, but "free" ids will be reused, trying to avoid "holes" in the tileset when tiles are removed.

Name Version Header Implementation
Tileset 0.6 tileset.h tileset.cpp

###Definitions Some definitions are given to use in the class (see all definitions and global variables in Reference page)

  • tile_id define the data type to store a tile id (the id referenced in a tileset and tilemap), currently defined as int.
  • static const tile_id null_tile_id=-1 tile_id default for null_tiles (see Reference)

###Variables Private

  • string name name (if any) of the tileset, currently unused, but it is recommended to set a different name for each tileset, so they may be differentiated
  • map<tile_id,tile> tile_list stores all the tiles, ordered by the tile_id (assigns one id per tile)
  • tile_id lowest_free represents the lowest id unused (to avoid having "holes" in the map)
  • unsigned int tile_size the width/height of a tile (in pixels)

Static

  • const static string tmx_tiletype_property defines the name of the property (by default tmx_tiletype_property="tiletype") where the tile_type will be defined on a tmx file (currently unused)

###Constructors

  • tileset() default constructors, with empty name, and tile size equals to 0,0, lowest_free will also equals 0
  • tileset(const Tmx::Tileset *ts) constructor from a tmx node for tileset, using tmx_tiletype_property for tile_type properties in tmx (currently unused)
  • tileset(const string &name,const ALLEGRO_BITMAP* bitmap,const vector<tile_type> & types,unsigned int tile_size,int ntiles=-1) full constructor of a tileset, given by a name, a bitmap (which will be sliced into ntiles tiles with [slice_bitmap](Al Utils)), tiles types are given in the types vector, and each tile size is given with width and height, if ntiles<=0, it will generates all the possible tiles in the bitmap
  • tileset(const ALLEGRO_BITMAP* bitmap,const vector<tile_type> &types,unsigned int tile_size,int ntiles=-1) same as full constructor but without a name (which will be an empty name by default)
  • tileset(const string &name,const tile &t,unsigned int tile_size) full constructor with only one tile (wich will be copied)
  • tileset(const tile &t,unsigned int tile_size) constructor with one tile without name
  • tileset(const tile &t) simple constructor from one tile, size of tileset will be set from the tile given

###Destructor

  • ~tileset() clear tile_list (erasing all tiles in tileset)

###Methods Public

  • tile_id add_tile(tile_type type,const ALLEGRO_BITMAP *bitmap) creates a new tile with given type and bitmaps and adds it to the tileset returning the id
  • tile_id add_tile(const tile &t) adds the tile (copying into a new tile) to the tileset and returns the id
  • vector<tile_id> load_from_bitmap(const ALLEGRO_BITMAP* bitmap,const vector<tile_types> & types,unsigned int tile_size,int ntiles) slices ntiles from the given bitmap (each tile with given tile_size) assigning to each one the type given by types vector and adding to the tileset, if ntiles<=0 all possible tiles will be sliced, if types vector size is less than sliced bitmaps, all new bitmaps will have the default parameter null_tile for its type, the returning vector will have all the ids of the sliced tiles (size of vector should be same as ntiles if >0)
  • void remove_tile(tile_id id) remove tile with given id (reassigning lowest_free if necessary)
  • void set_name(const string &name) set tileset name
  • bool is_tile(tile_id id) const return true if exists a tile with given id in tileset
  • unsigned int size() const returns the size of the tileset
  • unsigned int get_tile_width() const returns the width of a tile (in pixels) (tile_size)
  • unsigned int get_tile_height() const returns the height of a tile (in pixels) (same as get_tile_width()
  • string get_name() const returns tileset name
  • tile_type get_tile_type(tile_id id) const returns tile type of the tile with given id
  • void draw_tile(tile_id id,float x,float y) const draw the tile given by the tile_id in the position (x,y) (centered)
  • void draw_resized_tile(tile_id id,float x,float y,unsigned int tile_size) const draw the tile bitmap scaled to given tile_size
  • void resize_tileset(int tile_size) resize all the bitmaps of the tileset to the given size All the bitmaps will be resized permanently, so you will never recover the original bitmaps...ever
  • void add_tmx_tileset(const Tmx::Tileset *ts) adds another tmx tileset to current tileset, reassignind ids if necessary currently unused
  • bool check() const checks that all tiles in tileset have the tileset size

Private

  • tile_id get_next_free_id() const returns the next free id in the map (after the current lower_free)

DCmC Wiki 0.7.6

Clone this wiki locally