moving a image
I suggest you follow the link tentoid posted, it is the documentation for that paticuliar SDL function. Or you could go on with your tutorial, as I'm sure it'll come to this at some point...
his tutorial doesnt tell me about it, and another one about the function that i found it google doesnt explain it to me neither or I just dont understand it :P They talk about SDL_MapRGP or something :S
anyway thanks everybody for the help :)
anyway thanks everybody for the help :)
Quote:Original post by Toadhead
his tutorial doesnt tell me about it, and another one about the function that i found it google doesnt explain it to me neither or I just dont understand it :P They talk about SDL_MapRGP or something :S
anyway thanks everybody for the help :)
SDL_MapRGB
Uint32 SDL_MapRGB(SDL_PixelFormat *fmt, Uint8 r, Uint8 g, Uint8 b);
Usage:
Uint32 colour = SDL_MapRGB(my_screen->format, R, G, B);
So you pass the red, green and blue components of the colour. For example 255, 0, 0 would be bright red etc. White would be 255, 255, 255.
Example:
SDL_FillRect(my_screen, NULL, SDL_MapRGB(my_screen->format, 255, 255, 255)); // Fill the whole my_screen with red
If you want to fill the surface with black you can just pass 0 as the last parameter to SDL_FillRect.
I hope I've been helpful..
Oh and learn to use the SDL documentation. It will perhaps take some time but you can't really live without it [smile]
yeah it is..
I will also try SDL_FreeSurface(image); now instead of SDL_FillRect(); and see whats will happen :/
edit: damn it will completely delete the image and not clear the draw :(
I will also try SDL_FreeSurface(image); now instead of SDL_FillRect(); and see whats will happen :/
edit: damn it will completely delete the image and not clear the draw :(
Btw can anyone tell me the difference between:
and:
I'm not noticing any difference :(
Uint8 keys[500];keys = SDL_GetKeyState(NULL); if ( keys[SDLK_LEFT] ) {xpos -= 1; } if ( keys[SDLK_RIGHT] ) {xpos += 1; } if ( keys[SDLK_DOWN] ) {ypos += 1; } if ( keys[SDLK_UP] ) {ypos -= 1; }
and:
if ( event.key.keysym.sym == SDLK_LEFT ) {xpos -= 1; }if ( event.key.keysym.sym == SDLK_RIGHT] ) {xpos += 1; }if ( event.key.keysym.sym == SDLK_DOWN] ) {ypos += 1; }if ( event.key.keysym.sym == SDLK_UP] ) {ypos -= 1; }
I'm not noticing any difference :(
Quote:
I will also try SDL_FreeSurface(image); now instead of SDL_FillRect(); and see whats will happen :/
FreeSurface() destroys the image and frees the memory (it can't be used anymore, it doesn't exist in the memory). You need to call SDL_FreeSurface() on all your surfaces before your app closes (so there won't be any memory leaks).
SDL_FillRect() fills a rectangular area with a certain colour.
Quote:Original post by Toadhead
Btw can anyone tell me the difference between:
*** Source Snippet Removed ***
and:
*** Source Snippet Removed ***
I'm not noticing any difference :(
I think the latter one is the "correct way" to do it (browse the documentation wiki, there's something about it I think). You might want try using a switch().
switch(event.key.keysym.sym) { case SDLK_LEFT: MoveLeft(); break; // always remember to break // blah . // blah . case SDLK_UP: MoveUp(); break; default: break;}
Quote:Original post by Toadhead
Btw can anyone tell me the difference between:
*** Source Snippet Removed ***
and:
*** Source Snippet Removed ***
I'm not noticing any difference :(
I would recommend creating a user controls array which holds flags of every control that the user needs. Update it inside the while loop and then make use of it outside. This way you have the ability to easily change the user controls if needed.
Quote:Original post by Toadhead
Btw can anyone tell me the difference between:
*** Source Snippet Removed ***
and:
*** Source Snippet Removed ***
I'm not noticing any difference :(
The first method is called polling and the second method uses messaging. The second method is better than the first, in this case, because instead of asking SDL every single game loop whether a key has been pressed, you can just wait for SDL to tell you when a key has been pressed. So obviously polling is less efficient. It does have its uses, but not here.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement