开发者

How are game event lengths handled in 2D games

I have an idea of how I want to approach this but i'm not sure if it is ideal. By event I mean for example, if the player wins, a bunch of sparks fly for 1 second. I was thinking of creating my game engine class, then creating a game event base class that has 3 void functions, update, draw, render. There could be for example fireforks for collecting 100 coins for 3 seconds. The way I want to implement it is by having an event vector in my game engine where I can push the fireforks animation in. once something is pushed in the vector, the game does event[i].render() etc... For removing it I thought that each event could have an event length in frames, and each frame a uint is incre开发者_JS百科ased, if the uint matches the length, it is popped from the vector. I just wasnt sure if doing it like this was the best way.

Thanks


I would have each event instance have a method called isDone, or something like that. Then, for each frame, iterate through your events and:

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

Doing it this way allows for easier changes in the future. Not all events will last for a fixed amount of time (this might not be true for your game), some might even depend on things other than the current frame.

But in your eventBaseClass, you could define isDone as:

return this.endFrame >= game.currentFrame;

and override it in any events that you need to.


There are many, many different ways to skin this cat. For example, one of your routines could return a bool indicating whether or not this animation should be popped off the animation queue. I'm not sure what the differences are between update, draw and render, but all that is besides the point...

My recommendation would be to read. Read up on what other animation engines are doing, go find a good graphics programming gems book, and glean ideas and techniques from preexisting and established implementations. An even better solution would be to use one of them, saving you much pain and agony.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜