cross-platform code
I'm making a little game to try SDL and implementaton files
I've created a "ship" class with a function handling its movements
the problem is that my wonderful triangle won't move from the start point!
I've created a "ship" class with a function handling its movements
Code:
void astronave::controllanave() {
SDL_Event event;
glLoadIdentity();
glTranslatef(x, y, -10.0f);
glColor3f(1.0f, 0.0f, 0.0f);
glBegin(GL_LINE_LOOP);
glVertex2f(0.0f, 1.0f);
glVertex2f(-1.0f, 0.0f);
glVertex2f(1.0f, 0.0f);
glEnd();
x += vx;
y += vy;
while ( SDL_PollEvent (&event) ) {
switch (event.type) {
case SDLK_UP:
vy = 0.2f;
break;
case SDLK_DOWN:
vy = -0.2f;
break;
case SDLK_LEFT:
vx = -0.2f;
break;
case SDLK_RIGHT:
vx = 0.2f;
break;
default:
break;
}
}
}the problem is that my wonderful triangle won't move from the start point!
If I'm not entirely mistaken, you're getting stuck in an infinite loop. I don't know how the rest of your code looks, but I suggest that you re-build it a little bit.
You already have the concept of a "main loop" down, but in the wrong place. When you start the game, you should trap yourself in that while() loop you've written. From within it, you should update and draw the ship as needed.
More like:
You see, what happens there is that you enter the movement function, draw the ship, and then get stuck receiving events. But, you never exit that while loop, so you never redraw.
Check out some of the SDL tutorials on libsdl.org!
You already have the concept of a "main loop" down, but in the wrong place. When you start the game, you should trap yourself in that while() loop you've written. From within it, you should update and draw the ship as needed.
More like:
Code:
while (SDL_PollEvent (&event))
{
switch_and_stuff();
update_ship();
draw_ship();
}You see, what happens there is that you enter the movement function, draw the ship, and then get stuck receiving events. But, you never exit that while loop, so you never redraw.
Check out some of the SDL tutorials on libsdl.org!
Fenris Wrote:If I'm not entirely mistaken, you're getting stuck in an infinite loop. I don't know how the rest of your code looks, but I suggest that you re-build it a little bit.
You already have the concept of a "main loop" down, but in the wrong place. When you start the game, you should trap yourself in that while() loop you've written. From within it, you should update and draw the ship as needed.
More like:
Code:
while (SDL_PollEvent (&event))
{
switch_and_stuff();
update_ship();
draw_ship();
}
You see, what happens there is that you enter the movement function, draw the ship, and then get stuck receiving events. But, you never exit that while loop, so you never redraw.
Check out some of the SDL tutorials on libsdl.org!
ah ok! tnx for the help!
I'll check the tutorials as soon as I have more time!
wrong thread
umm I was wondering if SDL_GetTick() is precise enough, or if it's better to use OS' specific code... what do you think?
SDL_GetTick() is at least 1/60 seconds fidelity. For fast, fast games, that might be a little low, but I can almost guarantee you that it is above millisec fidelity on Mac OS X... So I wouldn't worry.
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Cross platform question | kordeul | 13 | 4,760 |
Aug 22, 2007 03:09 AM Last Post: kordeul |
|
| Cross-platform gui? | Duane | 13 | 4,735 |
Jul 6, 2007 06:38 PM Last Post: mac_girl |
|
| Best cross platform API for PC & MAC | Tarek Demiati | 6 | 2,947 |
Apr 16, 2006 03:07 PM Last Post: Dan Potter |
|
| Cross platform game code on a budget | Carlos Camacho | 7 | 3,416 |
Apr 19, 2003 09:29 PM Last Post: Mars_999 |
|
| Cross-platform Solutions | DJBlufire | 13 | 4,647 |
Feb 16, 2003 02:40 PM Last Post: athomson |
|

