class help
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]
June 01, 2004 01:37 AM
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.
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
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
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]
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 :DDrawline(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]
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:
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
For instance pseudo-code:
Create stl vector to hold class LINE objectsopen file handle to "line-file.cfg"read in file For each line, create a new LINE object Push the LINE object into the vectorContinue until end of file.Create a vector iterator for the line VectorFor( the beginning of the vector; until the last item; inc by 1) call RENDER on the object pointed to by the iteratorEnd ForDone
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
"C and C++ programmers seem to think that the shortest distance between two points is the great circle route on a spherical distortion of Euclidean space."Stephen Dewhurst
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]
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]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement