Problem with setting SDL_Rect up

Started by
5 comments, last by Stephen R 18 years, 11 months ago
Me again, I've got another problem (getting beyond a joke, I haven't even finished one game in SDL yet):

struct pong_ball
{
       
       vector2f *position;
       
       vector2f *direction;
       
       float speed;
       
       pong_ball()
       {
                  position=new vector2f(WINDOW_WIDTH/2,WINDOW_HEIGHT/2);
                  
                  direction=new vector2f(1.0,1.0);
                 
                  speed=0.5f;
       }
       
};

pong_ball g_ball;

void ball_draw()
{
     
     SDL_Rect ballrect;
     
     ballrect.x=g_ball.position.x;
     
     ballrect.y=g_ball.position.y;
     
     SDL_BlitSurface(ball,NULL,GameWindow,&ballrect);
     
}




On compile, it says: 53 C:\Documents and Settings\FINALPONG\main.cpp `x' has not been declared 53 C:\Documents and Settings\FINALPONG\main.cpp request for member of non-aggregate type before ';' token 55 C:\Documents and Settings\FINALPONG\main.cpp `y' has not been declared 55 C:\Documents and Settings\FINALPONG\main.cpp request for member of non-aggregate type before ';' token I've tried


position.x=new vector2f(WINDOW_WIDTH/2);
position.y=new vector2f(WINDOW_HEIGHT/2);


but it didn't like that either (even more errors). Any ideas? I'm stumped, never tried to do this before so I don't know a way round it. Thanks, ukdeveloper.
Advertisement
g_ball.position.x should be g_ball.position->x. The same goes for the y line.
Bloody hell, that was quick!

Yes, that works. Rating++;
Because your pong_ball struct's constructor allocates memory with new, it should have a destructor which frees the memory.
I don't intend to be rude, but maybe you should walk a little and re-read a few tutorials on pointers, re-read the book on C++(at least the basics like classes and operator overloading etc) and then come back to this. Like maybe give it a week.

I know you are dying to complete a game but patience is bitter, the fruits are sweet.
The more applications I write, more I find out how less I know
Quote:Original post by CRACK123
I don't intend to be rude, but maybe you should walk a little and re-read a few tutorials on pointers, re-read the book on C++(at least the basics like classes and operator overloading etc) and then come back to this. Like maybe give it a week.

I know you are dying to complete a game but patience is bitter, the fruits are sweet.


I know, I appreciate what you're saying, but I've done work on pointers before, and classes. It's the first time I've used them with regards to graphics though. If this was an ordinary text-based, non-game-whatsoever program there wouldn't be any problem, I don't think.

Or maybe I'm just not made for game programming, who knows.

Quote:Original post by ukdeveloper
Or maybe I'm just not made for game programming, who knows.

No dude, almost everyone has to work on the concept of pointer and object oriented code when they are new to programming. You've made the mistake, correct it, learn from it and continue on. Then the next time you write a program you won't make that mastake again, you'll make bigger, better mistakes [grin].

This topic is closed to new replies.

Advertisement