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

Tileset

demiurgosoft edited this page Nov 21, 2014 · 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.

Tileset is defined in the files tileset.h and tileset.cpp

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

To see the latest version, Click here

###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.

###Variables Private

  • map<tile_id,tile> tile_list stores all the tiles, ordered by the tile_id (assigns one id per tile)
  • string name name (if any) of the tileset
  • 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
  • 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,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(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)

###Destructor

  • ~tileset() destroy all the bitmaps of each tile in the tile_list

###Methods

Public

  • unsigned int size() const returns the size of the tileset
  • tile get_tile(tile_id id) const returns the tile defined by the tile_id (seriously, if you don't understand the description, go back to the Documentation Page
  • 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
  • void draw_tile(tile_id id,float x,float y) const draw the tile given by the tile_id in the position (x,y)
  • void draw_scaled_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 destroy_tileset() destroy all the bitmaps of the tiles, clear the tile_list and the name and set tile_height and tile_width to 0

Private

  • bool add_tile(tile_id id,tile_type type,ALLEGRO_BITMAP* bitmap) create a new tile with the given parameters, return true if a new tile was inserted, false if the given id was already on use
  • void load_from_bitmap(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, 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, all tiles will have an id from 0 to ntiles
  • void check() check that the class is working properly, reporting any warning or error with [debug_log](Debug Log)

DCmC Wiki 0.7.6

Clone this wiki locally