Class cocos.tiles.RectMapCollider

This class implements collisions between a moving rect object and a tilemap.

Methods

  collide_bottom(self, dy)
  collide_left(self, dx)
  collide_right(self, dx)
  collide_top(self, dy)
  collide_map(self, map, last, new, dy, dx)
Collide a rect with the given RectMap map.
  do_collision(self, cell, last, new, dy, dx)
Collide a Rect moving from "last" to "new" with the given map RectCell "cell".

Method Details

collide_map

collide_map(self, map, last, new, dy, dx)

Collide a rect with the given RectMap map.

Apart from "map" the arguments are as per do_collision.

Mutates the new rect to conform with the map.

Returns the (possibly modified) (dx, dy)

do_collision

do_collision(self, cell, last, new, dy, dx)

Collide a Rect moving from "last" to "new" with the given map RectCell "cell". The "dx" and "dy" values may indicate the velocity of the moving rect.

The RectCell must have the boolean properties "top", "left", "bottom" and "right" for those sides which the rect should collide.

If there is no collision then nothing is done.

If there is a collision:

  1. The "new" rect's position will be modified to its closest position to the side of the cell that the collision is on, and
  2. If the "dx" and "dy" values are passed in the methods collide_<side> will be called to indicate that the rect has collided with the cell on the rect's side indicated. The value passed to the collide method will be a modified distance based on the position of the rect after collision (according to step #1).

Mutates the new rect to conform with the map.

Returns the (possibly modified) (dx, dy)