I'm starting with C++ in more depth while building a simple 2d game engine. In my engine I have (or want to have) an "Abstract" GameEntity
class, which carries the methods draw
, update
, and maybe position
(x, y). I will add more stuff while it occurs to me.
Classes to inherit from GameEntity
would be anything that could be drawn on screen (ParticleSystem
, MovingSprite
, StaticSprite
, GuiMenu
, etc...)
My problem is that to achieve that, I have declared GameEntity
draw()
and update()
methods virtual:
virtual draw()=0;
virtual update()=0;
So ParticleSystem
has it's own draw and MovingSprite
also has it's own draw()
(and update()
).
I know virtual functions are expensive, or at least more expensive than regular methods. Do you think that what I'm doing is awful? Or too bad? If you do, I would really appreciate a better way to do this.
Thanks!