ESP32VGA
ESP32 VGA Controller and Graphics Library
Public Member Functions | List of all members
FabGL::Scene Class Referenceabstract

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...
 

Detailed Description

Scene is an abstract class useful to encapsulate functionalities of a scene (sprites, collision detector and updates).

Constructor & Destructor Documentation

◆ Scene()

FabGL::Scene::Scene ( int  maxSpritesCount,
int  updateTimeMS = 20,
int  width = Canvas.getWidth(),
int  height = Canvas.getHeight() 
)

The Scene constructor.

Parameters
maxSpritesCountSpecifies maximum number of sprites. This is required to size the collision detector object.
updateTimeMSNumber of milliseconds between updates. Scene.update() is called whenever an update occurs.
widthThe scene width in pixels.
heightThe scene height in pixels.

Member Function Documentation

◆ addSprite()

void FabGL::Scene::addSprite ( Sprite sprite)
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.

◆ 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
spriteAOne of the two sprites collided. This is the same sprite specified in Scene.updateSpriteAndDetectCollisions() call.
spriteBOne of the two sprites collided.
collisionPointCoordinates of a collision point.

◆ getHeight()

int FabGL::Scene::getHeight ( )
inline

Return scene height.

Returns
Scene height in pixels.

◆ getWidth()

int FabGL::Scene::getWidth ( )
inline

Return scene width.

Returns
Scene width in pixels.

◆ start()

void FabGL::Scene::start ( bool  suspendTask = true)

Start scene updates and suspends current task.

Parameters
suspendTaskIf true (default) current calling task is suspended immeditaly.

Example:

void loop()
{
  GameScene gameScene;
  gameScene.start();
}

◆ updateSprite()

void FabGL::Scene::updateSprite ( Sprite sprite)
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.

◆ updateSpriteAndDetectCollisions()

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.


The documentation for this class was generated from the following files: