/**
 * \brief Enables the pixel-perfect collision detection for this animation.
 */
void SpriteAnimation::enable_pixel_collisions() {

  if (src_image != NULL) {
    do_enable_pixel_collisions();
  }
  else {
    // wait for the source image to be available before analyzing its pixels
    should_enable_pixel_collisions = true;
  }
}
Example #2
0
/**
 * \brief When the sprite is displayed on a map, sets the tileset.
 *
 * This function must be called if this sprite image depends on the map's tileset.
 *
 * \param tileset The tileset.
 */
void SpriteAnimation::set_tileset(Tileset& tileset) {

  if (!src_image_is_tileset) {
    // Nothing to do when the tileset changes.
    return;
  }

  src_image = tileset.get_entities_image();
  if (should_enable_pixel_collisions) {
    disable_pixel_collisions(); // to force creating the images again
    do_enable_pixel_collisions();
  }
}