Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

kc_0045

class help

This topic is 5224 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hmm well iv just been starting to make my own game :D but im having problems with class. like say i want a class to run a function each frame how would i do that? i used this Tut http://cone3d.gamedev.net/cgi-bin/index.pl?page=tutorials/groundsup/tut5 but say i wanna make a render function that well be called each step for each classe thing how would i do that? im still rather new so ya :D thanks in advanced [edited by - kc_0045 on June 1, 2004 1:31:45 AM]

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
I''d hate to say this... cus it seems mean & impersonal... but you have gone through some of the tutorials on this site? do you know what a loop is? just promise to go through the first 5, then you will know the answer to your simple Q & so much more.

Share this post


Link to post
Share on other sites
ag i know that its just kinda hard to put into words..lol but ya just forget i asked i found a tut that well tell me all i want :D

Share this post


Link to post
Share on other sites
ok ya never mind it didnt help but heres what i ment :D

ok so this is just a EG but ya :D
so i have my class set up like this

class LINE
{
public:
LINE::LINE(int Xa_value, int Ya_value,int Xb_value, int Yb_value)
RENDER();

private:
int xa;
int ya;
int xb;
int yb;
};

LINE::LINE(int Xa_value, int Ya_value,int Xb_value, int Yb_value)
{
xa = Xa_value;
ya = Ya_value;
xb = Xb_value;
yb = Yb_value;
}

LINE::RENDER()
{
//Draw code here :D
Drawline(xa,ya,xb,yb);
}


i just typed that up so idk if theres errors :D but now say i want it to call the render function each frame for each LINE that there is. like if i go..

LINE L_a(0,50,50,0);
LINE L_b(50,50,50,0);
i dont have to call the render function by going...
L_a.RENDER();
L_b.RENDER();
each frame do i? liek is there away to make like a for function to cycle though them all?

[edited by - kc_0045 on June 1, 2004 8:21:39 PM]

Share this post


Link to post
Share on other sites
What you want to do is put your class in a higher level construct, like a vector (STL) or an array. This simplifies the management code.

For instance pseudo-code:


Create stl vector to hold class LINE objects
open file handle to "line-file.cfg"
read in file
For each line, create a new LINE object
Push the LINE object into the vector
Continue until end of file.

Create a vector iterator for the line Vector
For( the beginning of the vector; until the last item; inc by 1)
call RENDER on the object pointed to by the iterator
End For

Done



You can do this with an array as well, in *very simple terms* its the same thing but I would encourage you to spend the energy to understand STL and make use of it. "STL programming from the ground up" from Schildt is a pretty good reference and worth your time.

Side note - as you may be starting to see, this may not be the best (scalable?) way to accomplish what you are doing. Think of other ways to do this that may be more useful as your game code grows - think in terms of what you will need in the end.


Hope that helps -

#dth-0


Share this post


Link to post
Share on other sites
ok well im trying to make it so it keeps each instance in a array but i cant seem to get it to work :S hmm is there even anyway i can do this? like go...

LINE line1;
int array[3]=line1;
array[3].x=4;

?? if not thats my prob...well thanks for helping me :D

[edited by - kc_0045 on June 5, 2004 3:58:58 PM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!