0
\$\begingroup\$

I am fairly new to game development, but I have a good programming background with object oriented programming.

But with games, I do not know when I should use an object (or class) for an entity on the screen or whether I should just draw the images straight to the screen.

I think that for any graphic objects that need interacting with (say the player or certain environment objects) would need their own class and just decoration (the image that make up the background) could be drawn straight to the screen.

So, my question is: when do I use an object or class for my graphics?

If it makes any difference, I am using LibGDX.

\$\endgroup\$
3
  • 1
    \$\begingroup\$ This essentially boils down to the question "when do I use classes versus free functions?" which is not game-development specific and is also a very broad and discussion-oriented topic. Considering editing your question with details about your specific problem to address those issues. \$\endgroup\$ Commented Dec 6, 2013 at 3:31
  • \$\begingroup\$ No, I am talking about when to use them in a game. Specifically a game. So, when do I use a class for my images (e.g. a class for a "monster") or just load a picture onto the screen as a background. It is game-development specific and is not very broad. My specific question and details are written. \$\endgroup\$ Commented Dec 7, 2013 at 4:10
  • \$\begingroup\$ There no one answer, and the decision making process you would go through is the same as the process you'd use when deciding for any interface not just images. \$\endgroup\$ Commented Dec 7, 2013 at 16:34

1 Answer 1

0
\$\begingroup\$

It does often depend on what kind of interface the library/language provides and what kind of game it is there is no real right answer. If for example you have a 2D game using a tilemap, I prefer using some form of class/structure to keep the properties together, but if the background lacks properties that might be used to handle say collision it can as you say just be drawn to the screen as in LibGDX you can store the X and Y coordinate in the Sprite class which will be ultimately used to draw any decoration images which you could store in a collection.

Generally as long as you don't go crazy with inheritance classes will not create much of an overhead if you prefer thinking about things as objects it will probably make it easier for you to make your game.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Thank you for your response. So then with my game, I'll use objects for main entities (players and intractable environment, etc.) and just a manager class for the extra art which makes up the background. \$\endgroup\$ Commented Dec 6, 2013 at 2:32

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.