ESP32VGA
ESP32 VGA Controller and Graphics Library
|
Scene is an abstract class useful to encapsulate functionalities of a scene (sprites, collision detector and updates). More...
#include <scene.h>
Public Member Functions | |
Scene (int maxSpritesCount, int updateTimeMS=20, int width=Canvas.getWidth(), int height=Canvas.getHeight()) | |
The Scene constructor. More... | |
int | getWidth () |
Return scene width. More... | |
int | getHeight () |
Return scene height. More... | |
void | start (bool suspendTask=true) |
Start scene updates and suspends current task. More... | |
void | stop () |
Stop scene updates and resumes suspended task. | |
virtual void | init ()=0 |
This is an abstract method called when the scene needs to be initialized. | |
virtual void | update (int updateCount)=0 |
This is an abstract method called whenever the scene needs to be updated. | |
virtual void | collisionDetected (Sprite *spriteA, Sprite *spriteB, Point collisionPoint)=0 |
This is an abstract method called whenever a collision has been detected. More... | |
void | addSprite (Sprite *sprite) |
Add the specified sprite to collision detector. More... | |
void | removeSprite (Sprite *sprite) |
Remove the specified sprite from collision detector. | |
void | updateSprite (Sprite *sprite) |
Update collision detector. More... | |
void | updateSpriteAndDetectCollisions (Sprite *sprite) |
Update collision detector and generate collision events. More... | |
Scene is an abstract class useful to encapsulate functionalities of a scene (sprites, collision detector and updates).
FabGL::Scene::Scene | ( | int | maxSpritesCount, |
int | updateTimeMS = 20 , |
||
int | width = Canvas.getWidth() , |
||
int | height = Canvas.getHeight() |
||
) |
The Scene constructor.
maxSpritesCount | Specifies maximum number of sprites. This is required to size the collision detector object. |
updateTimeMS | Number of milliseconds between updates. Scene.update() is called whenever an update occurs. |
width | The scene width in pixels. |
height | The scene height in pixels. |
|
inline |
Add the specified sprite to collision detector.
The collision detector is updated calling Scene.updateSprite() or updateSpriteAndDetectCollisions(). The number of sprites cannot exceed the value specified in Scene constructor.
|
pure virtual |
This is an abstract method called whenever a collision has been detected.
This method is called one o more times as a result of calling Scene.updateSpriteAndDetectCollisions() method when one o more collisions has been detected.
spriteA | One of the two sprites collided. This is the same sprite specified in Scene.updateSpriteAndDetectCollisions() call. |
spriteB | One of the two sprites collided. |
collisionPoint | Coordinates of a collision point. |
|
inline |
Return scene height.
|
inline |
Return scene width.
void FabGL::Scene::start | ( | bool | suspendTask = true | ) |
Start scene updates and suspends current task.
suspendTask | If true (default) current calling task is suspended immeditaly. |
Example:
void loop() { GameScene gameScene; gameScene.start(); }
|
inline |
Update 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. To generate collision events call Scene.updateSpriteAndDetectCollisions instead.
void FabGL::Scene::updateSpriteAndDetectCollisions | ( | Sprite * | sprite | ) |
Update collision detector and generate collision events.
When a sprite changes its position or size it is necessary to update the collision detector. This method updates the detector and generates collision events accordly.