Jump to content

View more

Image of the Day

WIP title screen for #DeathOfAPartisan #screenshotsaturday #gamedev https://t.co/qJNhfZCvd4
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

Sign up now

Is creating an drawing class a good idea?

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 GDsnakes   Members   


Posted 14 January 2013 - 10:38 AM

Say a class with data members Xposistion, Y position, etc





Quaddraw Quad(X,Y,etc)



then in main game loop. Make a call to...



Quad.show(); //draws in position X/Y





I was trying to do this and its wasn't working.

#2 smr   Members   


Posted 14 January 2013 - 10:51 AM

I'm not exactly sure how you're planning on using this, but yes, it's probably a bad idea.


If the goal of creating classes to represent my application is abstraction, then I probably don't want my game logic to have to think in terms of quads, but rather in Sprites or Models or Tiles or whatever it is that is actually being represented. That is of course unless you actually are just drawing quads to the screen...


In your renderer, you may want to treat quads as data and as items to perform calcualtions on, but you probably won't be drawing individual quads, as you'll be batching them and storing their indices in vertex lists and things like that which muddy up the definition of when a quad is actually "drawn."

#3 Geometrian   Members   


Posted 14 January 2013 - 05:19 PM

This kind of question needn't exist. There's two correct answers depending on your use case, inverses of each other.


Suppose I'm making a turn-based, tile-based game. Some tiles are larger than others (e.g. I plop down a city, and it covers four tiles instead of one). Then it might be a good idea to write a drawing class. The class can serve to cache these tiles, only update those that need to be changed, at the right framerate. With a bit of work, it could form the core of a graphics subsystem running on an independent thread from the rest of the game logic. This reflects the underlying program: your game might only update game mechanics once per turn, but the characters and cities and water in each tile need to update more often (the water has a wave animation that needs to run continuously, for example).


Suppose I'm making a 3D FPS game. The characters all need to run around and be animated, but this is handled through each object. Character Joe and Character Susan have different meshes, so while they might be children of the same subclass, they benefit from somewhat customized draw methods (Susan needs to be surrounded with a glow effect because she's special). And neither Joe nor Susan have anything in common with a building, which also knows how to draw itself. Trying to abstract the whole thing into a specialized drawing class that handles all these distinct cases would just overcomplicate things.


Which brings me to the most important point of all this. Design questions are almost always cut and dry if you know what your features are. Sure, there's a few different ways to do something, but there is almost always a best way, and it's almost always obvious with a little thought. My driving game needs to support both jeeps and sedans. Fine. Make them subclasses of a common class "Vehicle" or "Car". My flight simulator needs to have physically based wind simulation. Great. Tie that in with your physics engine, not your rendering backend.


As you become a better programmer, one thing I've noticed is that you increasingly just see what to do. It's just obvious. No one can tell you what the right design is unless they're working on the same project. Programming is all about just trying things and see what happens. In my experience, there are few applications for an abstracted, dedicated rendering class. But that doesn't mean that that's not necessarily the Right Thing. It's all up to you.

And a Unix user said rm -rf *.* and all was null and void...|There's no place like|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.

#4 TheChubu   Members   


Posted 14 January 2013 - 06:45 PM

I'm on the boat of people that says Objects shouldn't know how to draw themselves.


Main reason is to abstract game logic from rendering logic. You shouldn't make a game logic aspect (ie, a character, or a building) handle responsibilities that are inherent of another system.


Besides, having a draw method for each of your meshes/sprites/whatever leads to a lot of boilerplate code if many meshes are drawn the same.


While many objects could have different drawing requirements, often they're not that different that you can't make a class handle all the drawing instead. Its not like you need to have a "susan render" method, but you could just have a method that renders objects with effects, susan would have one attached to it, joe wont, and the rendering object will react accordingly.


If you change render objects along the road, you needn't to change every single draw method of all your objects, you should be able just to switch where the objects are sent to being drawn and that's it.



My journals: dustArtemis ECS framework and Making a Terrain Generator

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.