Class cocos.tiles.RectMap

RegularTesselationMap --+
                        |
                       RectMap
Known Subclasses:
RectMapLayer

Rectangular map.

Cells are stored in column-major order with y increasing up, allowing [i][j] addressing:

+---+---+---+
| d | e | f |
+---+---+---+
| a | b | c |
+---+---+---+

Thus cells = [['a', 'd'], ['b', 'e'], ['c', 'f']]

(and thus the cell at (0,0) is 'a' and (1, 1) is 'd')

Methods

  __init__(self, id, tw, th, cells, origin=None, properties=None)
  get_in_region(self, x1, y1, x2, y2)
Return cells (in [column][row]) that are within the map-space pixel bounds specified by the bottom-left (x1, y1) and top-right (x2, y2) corners.
  get_at_pixel(self, x, y)
Return Cell at pixel px=(x,y) on the map.
  get_neighbor(self, cell, direction)
Get the neighbor Cell in the given direction (dx, dy) which is one of self.UP, self.DOWN, self.LEFT or self.RIGHT.
  get_neighbors(self, cell, diagonals=False)
Get all cells touching the sides of the nominated cell.
  get_cell(self, i, j)
Return Cell at cell pos=(i, j).
(Inherited from cocos.tiles.RegularTesselationMap)

Constants

  UP = (0, 1)
  DOWN = (0, -1)
  LEFT = (-1, 0)
  RIGHT = (1, 0)

Method Details

__init__

(Constructor) __init__(self, id, tw, th, cells, origin=None, properties=None)
Parameters:
id : xml id
node id
tw : int
number of colums in cells
th : int
number of rows in cells
cells : container that supports cells[i][j]
elements are stored in column-major order with y increasing up
origin : (int, int, int)
cell block offset x,y,z ; default is (0,0,0)
properties : dict
arbitrary properties if saving to XML, keys must be unicode or 8-bit ASCII strings

get_in_region

get_in_region(self, x1, y1, x2, y2)

Return cells (in [column][row]) that are within the map-space pixel bounds specified by the bottom-left (x1, y1) and top-right (x2, y2) corners.

Return a list of Cell instances.

get_at_pixel

get_at_pixel(self, x, y)

Return Cell at pixel px=(x,y) on the map.

The pixel coordinate passed in is in the map's coordinate space, unmodified by screen, layer or view transformations.

Return None if out of bounds.

get_neighbor

get_neighbor(self, cell, direction)

Get the neighbor Cell in the given direction (dx, dy) which is one of self.UP, self.DOWN, self.LEFT or self.RIGHT.

Returns None if out of bounds.

get_neighbors

get_neighbors(self, cell, diagonals=False)

Get all cells touching the sides of the nominated cell.

If "diagonals" is True then return the cells touching the corners of this cell too.

Return a dict with the directions (self.UP, self.DOWN, etc) as keys and neighbor cells as values.