Jump to content
  • Advertisement
Sign in to follow this  
cr4sp

OOP Game Engine

This topic is 3205 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm currently building a little 2D oop game engine and I'm asking myself if I should separate the visual parts from the logical parts. For example I've got a class named sprite which contains all information needed to render a simple image to the screen (texture, position, scale ...). How should my avatar class, which contains all the (logical) information (like health) implement the needed sprites to be drawn to the screen? The avatar has a position, and if he moves the sprites have to move too. Should the avatar have a Draw method drawing all his sprites or should there be a render class to do this task? Should the sprites be in a collection of the avatar? Who sets the position of the sprites if the avatar moves? I could go on but I think you've got the point.

Share this post


Link to post
Share on other sites
Advertisement
Without knowing more I would think that the Avatar class can have any number of sprites. So I would recommend the Draw method. If the Draw method is related to some other more generic renderable object class. Then you can call draw on all your objects and each can draw using sprites or text or what ever else is needed.

Maybe the avatar holds a position value relative to the world and the sprites have a position value relative to the avatar. This would let your avatar draw using sprites for say a hat or pants or something. Then you would just move the avatar and everything would stay in position.

Share this post


Link to post
Share on other sites
Let the sprites be held and controlled by the Avatar class or any other actors, but also held in a container with all the other sprites in the game. When you update the game, the Avatar updates its logic and moves the sprite wherever it needs to go. Later in the update cycle, all the sprites can be drawn, independently of who controls them. At this point you can apply all sorts of interesting rendering optimizations.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!