|
FabGL
ESP32 VGA Controller and Graphics Library
|
A class to detect sprites collisions. More...
#include <collisiondetector.h>
Public Member Functions | |
| CollisionDetector (int maxObjectsCount, int width, int height) | |
| Creates an instance of CollisionDetector. More... | |
| void | addSprite (Sprite *sprite) |
| Adds the specified sprite to collision detector. More... | |
| Sprite * | detectCollision (Sprite *sprite, bool removeCollidingSprites=true) |
| Detects first collision with the specified sprite. More... | |
| void | detectCollision (Sprite *sprite, CollisionDetectionCallback callbackFunc, void *callbackObj) |
| Detects multiple collisions with the specified sprite. More... | |
| void | removeSprite (Sprite *sprite) |
| Removes the specified sprite from collision detector. More... | |
| void | update (Sprite *sprite) |
| Updates collision detector. More... | |
| Sprite * | updateAndDetectCollision (Sprite *sprite, bool removeCollidingSprites=true) |
| Updates collision detector and detect collision with the specified sprite. More... | |
| void | updateAndDetectCollision (Sprite *sprite, CollisionDetectionCallback callbackFunc, void *callbackObj) |
| Updates collision detector and detect multiple collisions with the specified sprite. More... | |
A class to detect sprites collisions.
CollisionDetector uses a Quad-tree data structure to efficiently store sprites size and position and quick detect collisions.
CollisionDetector is embedded in Scene class, so usually you don't need to instantiate it.
| fabgl::CollisionDetector::CollisionDetector | ( | int | maxObjectsCount, |
| int | width, | ||
| int | height | ||
| ) |
Creates an instance of CollisionDetector.
CollisionDetector is embedded in Scene class, so usually you don't need to instantiate it.
| maxObjectsCount | Specifies maximum number of sprites. This is required to size the underlying quad-tree data structure. |
| width | The scene width in pixels. |
| height | The scene height in pixels. |
| void fabgl::CollisionDetector::addSprite | ( | Sprite * | sprite | ) |
Adds the specified sprite to collision detector.
The collision detector is updated calling CollisionDetector.update() or CollisionDetector.updateAndDetectCollision().
The number of sprites cannot exceed the value specified in CollisionDetector constructor.
| sprite | The sprite to add. |
| Sprite * fabgl::CollisionDetector::detectCollision | ( | Sprite * | sprite, |
| bool | removeCollidingSprites = true |
||
| ) |
Detects first collision with the specified sprite.
It is necessary to call CollisionDetector.update() before detectCollision() so sprites position and size are correctly updated.
| sprite | The sprite to detect collision. |
| removeCollidingSprites | If true the collided sprites are automatically removed from the collision detector. |
| void fabgl::CollisionDetector::detectCollision | ( | Sprite * | sprite, |
| CollisionDetectionCallback | callbackFunc, | ||
| void * | callbackObj | ||
| ) |
Detects multiple collisions with the specified sprite.
It is necessary to call CollisionDetector.update() before detectCollision() so sprites position and size are correctly updated.
| sprite | The sprite to detect collision. |
| callbackFunc | The callback function called whenever a collision is detected. |
| callbackObj | Pointer passed as parameter to the callback function. |
| void fabgl::CollisionDetector::removeSprite | ( | Sprite * | sprite | ) |
Removes the specified sprite from collision detector.
| sprite | The sprite to remove. |
| void fabgl::CollisionDetector::update | ( | Sprite * | sprite | ) |
Updates collision detector.
When a sprite changes its position or size it is necessary to update the collision detector.
This method just updates the detector without generate collision events.
| sprite | The sprite to update. |
| Sprite * fabgl::CollisionDetector::updateAndDetectCollision | ( | Sprite * | sprite, |
| bool | removeCollidingSprites = true |
||
| ) |
Updates collision detector and detect collision with the specified sprite.
When a sprite changes its position or size it is necessary to update the collision detector.
This method updates the detector and detects collisions.
| sprite | The sprite to update and to check for collisions. |
| removeCollidingSprites | If true the collided sprites are automatically removed from the collision detector. |
| void fabgl::CollisionDetector::updateAndDetectCollision | ( | Sprite * | sprite, |
| CollisionDetectionCallback | callbackFunc, | ||
| void * | callbackObj | ||
| ) |
Updates collision detector and detect multiple collisions with the specified sprite.
When a sprite changes its position or size it is necessary to update the collision detector.
This method updates the detector and detects multiple collisions.
| sprite | The sprite to update and to check for collisions. |
| callbackFunc | The callback function called whenever a collision is detected. |
| callbackObj | Pointer passed as parameter to the callback function. |