Programming 2D Games

The official forum for "Programming 2D Games" the book by: Charles Kelly

It is currently Tue Apr 23, 2019 11:03 am

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: learning OOP
PostPosted: Tue Jan 07, 2014 12:26 am 
Offline
User avatar

Joined: Wed Oct 30, 2013 11:46 pm
Posts: 30
Hello,
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,
Cla


Top
 Profile  
Reply with quote  
 Post subject: Re: learning OOP
PostPosted: Sat Jan 11, 2014 3:36 pm 
Offline

Joined: Mon Dec 23, 2013 1:40 am
Posts: 37
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 : http://www.getcodesamples.com/src/F23D0C89/8071B66D

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.

Thanks


Top
 Profile  
Reply with quote  
 Post subject: Re: learning OOP
PostPosted: Sat Jan 11, 2014 8:58 pm 
Offline
Site Admin
User avatar

Joined: Sat Jan 28, 2012 4:36 pm
Posts: 551
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.

_________________
Professor Kelly


Top
 Profile  
Reply with quote  
 Post subject: Re: learning OOP
PostPosted: Sun Jan 12, 2014 7:40 am 
Offline
User avatar

Joined: Wed Oct 30, 2013 11:46 pm
Posts: 30
Thank you prof.
I am exploring polymorphism now.. Start understanding why C++ is so powerful!


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group