Programming 2D Games

learning OOP
Page 1 of 1

Author:  Cla [ Tue Jan 07, 2014 12:26 am ]
Post subject:  learning OOP

I would like to share an idea that I have for the framework I am making. I don't know if it's smart or stupid so feel free to give me your opinion as I am fairly new to OOP and programming in general.

I am trying to make a little 2D engine from scratch taking prof. Kelly's work as example.
Right now, it looks a lot like his framework in Chapter 5 but instead of having a "textureManager" and "Image" class, it only has a "sprite" class dealing with everything involving the texture etc.

Because this "sprite" class works fine but it doesn't have enough member variables to allow for animation, I was thinking: what about creating another class that inherit from "sprite" and calling it "animatedSprite" making it contain more info and hence enable it to handle animation.

AnimSprite IS A Sprite and each Sprite HAS A Texture, so it makes a lot of sense to me that Sprite objects should contain Texture objects and AnimSprite objects should inherit from Sprite objects.
Is this a good idea?

Also. I noticed that in the prof. Kelly's engine there are functions that let you choose the frame, the initial frame, the final frame etc.
This is very useful because you need only 1 single texture with all the frames for e.g. walking, standing, swimming and then you can select the right frames depending on the situation.
In this way it makes sense that, in Kelly's design, eah entity HAS 1 image that HAS 1 texture.

But wouldn't it be also nice to prepare your textures as if they were stripes with many frames where each frame represents 1 frame of animation and different textures represent different animations (go right, go left, swim up, etc ) and then say:
Each 1 entity HAS SEVERAL images (corresponding to several animations).

I guess the actual reason why i am asking this question is because I don't know whether I am going in the right direction with this OOP design ideas. For instance, the other day I made a Timer class and now I am not sure if it was a good idea or not. :lol:

Thanks for reading and happy programming,

Author:  SteveHatcher [ Sat Jan 11, 2014 3:36 pm ]
Post subject:  Re: learning OOP

I am by far an expert on the matter, but from my general readings as I have been dabbling with C++ it seems the best way to do things are the way that you, the programmer, feels most comfortable with. Let the compiler take care of the optimizations, and just focus on good, clean, understandable C++ code.

As for the timer class I don't see why not. Remember a lot of the functions you are using are just other classes put in by the C++ engineers (or whoever writes the source code files). For instance, I found a nice kind of template for DirectX 11 which contains a bunch of tools that could be used as a sort of framework for your own application :

They all seem to use that QueryPerformanceCounter either way, but again your own class means that you fully understand how to implement it in future projects. So maybe it is a good idea as it allows you to build up a 'library' or reusable functions.


Author:  profkelly [ Sat Jan 11, 2014 8:58 pm ]
Post subject:  Re: learning OOP

There is no "right" way to create something as complex as a game engine. One thing to keep in mind is that textures are usually stored in video memory as a square array of pixels who's edges are a power of 2 in size. Specifying a thin strip as a texture image will work, but might not be very efficient in terms of video memory usage.

Author:  Cla [ Sun Jan 12, 2014 7:40 am ]
Post subject:  Re: learning OOP

Thank you prof.
I am exploring polymorphism now.. Start understanding why C++ is so powerful!

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group