• Advertisement
Sign in to follow this  

SDL surface apply help

This topic is 2356 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

Here is a program that ive been working on. im trying to get a paddle for a game of pong im making to move down when i press the down key, but it moves down, but i can still see the old image :/ I think my apply function is messed up
Help would be appreciated
BTW the image_load.h is just IMG_Load inside a separate header
#include <SDL.h>
#include "image_load.h"

SDL_Rect source;
SDL_Rect dest;
int abc = 20;
SDL_Surface *screen = NULL;
SDL_Surface *paddle = NULL;

void apply_surface(int );

int main(int argc, char* args[])
{
SDL_Init(SDL_INIT_EVERYTHING);


screen = SDL_SetVideoMode(800, 600, 32, SDL_SWSURFACE);

char *filename = "paddle.png";
paddle = load_image(filename);


apply_surface(20);
SDL_Event event;
bool quit = false;

while(quit == false)
{
if(SDL_PollEvent(&event))
{
if(event.type == SDL_KEYDOWN)
{
switch(event.key.keysym.sym)
{
case SDLK_DOWN: apply_surface(abc); abc = abc + 10; break;
case SDLK_ESCAPE: quit = true; break;
default: ;
}
}
if(event.type == SDL_QUIT)
{
quit = true;
}
}
}
SDL_FreeSurface(paddle);
SDL_Quit();
return 0;
}

void apply_surface(int abcd)
{
source.x = 0;
source.y = 0;
source.w = 5;
source.h = 100;

dest.x = 0;
dest.y = abcd;
dest.w = 5;
dest.h = 100;

SDL_BlitSurface(paddle, &source, screen, &dest);
SDL_Flip(screen);
}

Share this post


Link to post
Share on other sites
Advertisement
If you have a painting and draw an object at one spot and then draw the same object at another spot you will end up with two objects in your painting. One object will not magically disapear from the painting. If you don't want to have the first object you have to paint over it. The same apply here.

Share this post


Link to post
Share on other sites

If you have a painting and draw an object at one spot and then draw the same object at another spot you will end up with two objects in your painting. One object will not magically disapear from the painting. If you don't want to have the first object you have to paint over it. The same apply here.


How do i get rid of the original image then? Or is there a more efficient way of moving sprites around?

Share this post


Link to post
Share on other sites
You can blit part of the background over the sprite's previous location. Or blit the whole background before each time you update the screen.

Share this post


Link to post
Share on other sites

You can blit part of the background over the sprite's previous location. Or blit the whole background before each time you update the screen.

I think I know what you mean, I have a background image that I'm going to put in, so before I apply the paddle I apply the background everytime?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement