Jump to content

  • Log In with Google      Sign In   
  • Create Account

DirectX And Game Programming Organization


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 MrFraggs   Members   -  Reputation: 160

Like
0Likes
Like

Posted 17 June 2012 - 01:47 PM

Hey guys, i'm just starting some actual programming with DirectX, and I was hoping someone could go over my code so far and tell me how well it's organized, and how well I could fix it. Thanks! All the program does so far is display a sprite that moves itself across the screen.

Spoiler


Sponsor:

#2 bglanzer   Members   -  Reputation: 459

Like
0Likes
Like

Posted 17 June 2012 - 02:21 PM

There are lots of ways to do things and one way is not always best. Some methods may have advantages over others though. In your case you want to think about mobility and reusability. What if you wanted to make another game? You would have to retype or cut and paste all of your windows and directx initiallization over again. It might be easier to wrap everything up in classes and built into a library that way you can reuse it and spend more time programming gameplay rather than typing code to access hardware.

Brendon Glanzer


#3 MrFraggs   Members   -  Reputation: 160

Like
0Likes
Like

Posted 17 June 2012 - 02:37 PM

Well, aside from the sprite programming, I have the DirectX code set aside to reuse. What I was mainly asking though, which I see may have been a bit confusing, was that I was looking for advice on how to just make what I have so far cleaner, and maybe a better way to put all the sprite stuff into one class. I realize that there are many ways to do things, but I was looking for opinions on how to just make this code cleaner.

#4 bglanzer   Members   -  Reputation: 459

Like
0Likes
Like

Posted 17 June 2012 - 09:41 PM

In the case of your sprite I think its pretty good. Here is simple quick example of a sprite class I did in the past, just to give you an example of animated sprites

Hopefully the classes are understandable. Pretty much because animations can run at different speeds and a sprite can have many different animations you want to separate your sprite animations. Also it makes it easier to put things like positions and scale into class called Transform which is derived from a Component class. Then allow additional
components to be added that hold things like velocity, speed, bounding box, etc.

Currently what you have is good. But when you want to create more complex sprites below is a structure that worked for me.

****EDIT**** On second thought you might want Transform and Component under a GameObject class which Sprite is derived from.

class SpriteAnimation {
public:
//Set methods, Get methods, update method
protected:
	 int m_iCellWidth;
	 int m_iCellHeight;
	 int m_iFirstFrame;
	 int m_iLastFrame;
	 int m_iCurrentFrame;
	 int m_iAnimationDirection; // 1 for forward -1 for backward
  
	 bool m_bLoop;
	 bool m_bAnimating;
	 bool m_bCustomFrameList;
  
	 float m_fFrameDelay;
	 float m_fTimer;
	  TArray<int> customFrameArray;
};

class Sprite {
public:
	 //Constructors, Destructors, Setters, Getters
	 bool AddAnimation( SpriteAnimation* animation );
	 bool AddComponent( Component* component);

protected:
	 Transform m_transform; //transform hold position, scale, ect		  
	  TArray<Component *> m_components; //Holds any components
	  TArray<SpriteAnimations *> m_animations; //holds all animations
};

Edited by bglanzer, 17 June 2012 - 09:43 PM.

Brendon Glanzer





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.



PARTNERS