How the length of a game event is handled in 2D games

I have an idea how I want to approach this, but I'm not sure if it is perfect. For example, in the event of an event, if the player wins, a bunch of sparks flies for 1 second. I was thinking of creating my own class of game engine, and then creating a base class of a game event, which has 3 functions void, update, draw, render. Maybe, for example, fireforks to collect 100 coins in 3 seconds. The way I want to implement this is to have an event vector in my game engine where I can push the fireforks animation. Once, something is inserted into the vector, the game makes the [i] .render () event, etc ... deleting it, I thought that each event can have the length of the event in frames, and each uint frame is incremented, if uint matches the length, it is set from the vector. I was just not sure what to do, as it was in the best way.

thanks

+5
source share
2 answers

Each instance of the event has a method called isDone, or something like that. Then for each frame iterate over your events and:

if (event.isDone()) {
    //remove the event
} else {
    event.update();
}

The implementation of this method allows in the future to simplify the changes. Not all events will last a fixed time (this may not be true for your game), some may even depend on other things besides the current frame.

But in your eventBaseClass, you can define isDone as:

return this.endFrame >= game.currentFrame;

and override it in any events that you need.

+1
source

. , bool, , . , , , , ...

. , , . , .

+1

All Articles