|
-
Oct 31st, 2007, 03:52 PM
#1
Thread Starter
Frenzied Member
[C# 2005] DirectX Drawing and Class Design
Hey everyone!
I have been making a remake of Pong. I have wrote several classes such as Entity, Ball, Paddle, Engine, and TexManager. Ball and Paddle both inherit from Entity.
I have, however, come across a problem. How do I draw everything onto the screen? Of course I know how to draw them using a sprite object, a vector object, and texture object but that's not what I mean.
How could I have it versatile so it will draw all entities onto the screen? Let's say there are 4 paddles and 1 ball. All of these object have an overridden Draw method and inherit from Entity. What would be the object oriented way to do this?
I was thinking something like this (pseudocode) but I don't know how to implement it:
Code:
for each entity in the game
{
entity.Draw(device);
}
However, then I would need to have a global list and pass it around and such and wouldn't work out too well..
I really hope I could find a good, object oriented solution to this.
Also, a bit off topic but here's another question:
What would be a good way to implement a texture or object manager? Currently I have a TexManager class that you instantiate and load images into it via it's Load method and pass in the location on the hard drive of the image and the ID you want to associate it with. The class has a Dictionary inside of it to hold the textures corresponding id (int)
I also have a Retrieve method that returns the texture object for use via an ID parameter. In this case, I need to remember the ID of all the textures I load into the texture manager. What if I have around 20 textures? Then I need to remember 20 different integers! Surely there must be a better way! Perhaps have an enum or something but I wouldn't really be sure if that would be a good solution or even how to do it.
Since I already asked 2 questions, might as well ask a third.
I suppose I want each Ball object or Paddle object to have a draw method. Currently, they both inherit from an abstract Entity class. The Entity class is as follows:
Code:
public abstract class Entity
{
public abstract void Draw(Sprite device, TexManager texManager);
protected Vector3 location;
}
However, then I need to override Draw in every class that inherits from it.. I suppose it is a good design but it just doesn't seem right for some reason. Maybe it us, but some feedback on it would be great.
Well, hopefully I will get some feedback on this as I will greatly appreciate it. Thanks a bunch =)
-
Nov 4th, 2007, 10:53 PM
#2
Thread Starter
Frenzied Member
Re: [C# 2005] DirectX Drawing and Class Design
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|