Scene is an abstract class useful to encapsulate functionalities of a scene (sprites, collision detector and updates).
More...
#include <scene.h>
Scene is an abstract class useful to encapsulate functionalities of a scene (sprites, collision detector and updates).
◆ Scene()
fabgl::Scene::Scene |
( |
int |
maxSpritesCount, |
|
|
int |
updateTimeMS = 20 , |
|
|
int |
width = Canvas.getWidth() , |
|
|
int |
height = Canvas.getHeight() |
|
) |
| |
The Scene constructor.
- Parameters
-
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. |
◆ addSprite()
void fabgl::Scene::addSprite |
( |
Sprite * |
sprite | ) |
|
|
inline |
◆ collisionDetected()
virtual void fabgl::Scene::collisionDetected |
( |
Sprite * |
spriteA, |
|
|
Sprite * |
spriteB, |
|
|
Point |
collisionPoint |
|
) |
| |
|
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.
- Parameters
-
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. |
◆ getHeight()
int fabgl::Scene::getHeight |
( |
| ) |
|
|
inline |
Determines scene height.
- Returns
- Scene height in pixels.
◆ getWidth()
int fabgl::Scene::getWidth |
( |
| ) |
|
|
inline |
Determines scene width.
- Returns
- Scene width in pixels.
◆ init()
virtual void fabgl::Scene::init |
( |
| ) |
|
|
pure virtual |
This is an abstract method called when the scene needs to be initialized.
◆ removeSprite()
void fabgl::Scene::removeSprite |
( |
Sprite * |
sprite | ) |
|
|
inline |
Removes the specified sprite from collision detector.
- Parameters
-
sprite | The sprite to remove. |
◆ start()
void fabgl::Scene::start |
( |
bool |
suspendTask = true | ) |
|
Starts scene updates and suspends current task.
- Parameters
-
suspendTask | If true (default) current calling task is suspended immeditaly. |
Example:
void loop()
{
GameScene gameScene;
gameScene.start();
}
◆ stop()
void fabgl::Scene::stop |
( |
| ) |
|
Stops scene updates and resumes suspended task.
◆ update()
virtual void fabgl::Scene::update |
( |
int |
updateCount | ) |
|
|
pure virtual |
This is an abstract method called whenever the scene needs to be updated.
- Parameters
-
updateCount | Indicates number of times Scane.update() has been called. |
◆ updateSprite()
void fabgl::Scene::updateSprite |
( |
Sprite * |
sprite | ) |
|
|
inline |
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.
To generate collision events call Scene.updateSpriteAndDetectCollisions instead.
- Parameters
-
sprite | The sprite to update. |
◆ updateSpriteAndDetectCollisions()
void fabgl::Scene::updateSpriteAndDetectCollisions |
( |
Sprite * |
sprite | ) |
|
Updates 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.
- Parameters
-
sprite | The sprite to update and to check for collisions. |
The documentation for this class was generated from the following files: