#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#include <SDL/SDL_mixer.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <SDL/SDL_ttf.h>
int main (int argc,char *args[])
{SDL_Rect offset;int xb,yb;
xb=0;
yb=0;
int x=100;
int y=100;
int xvel=10;
int yvel=10;
SDL_Surface *screen=NULL;
SDL_Surface *back=NULL;
SDL_Surface *ennemi=NULL;
offset.x=0;
offset.y=0;
back = IMG_Load("back.jpg");
ennemi = IMG_Load("en.png");
screen = SDL_SetVideoMode(740,580,16,SDL_HWSURFACE);
SDL_BlitSurface(ennemi,NULL,screen,&offset);
apply_surface(xb,yb,back,screen);
while(1)
{
break;
x+=xvel;
apply_surface(x,y,ennemi,screen);
break;
x+=xvel;
apply_surface(x,y,ennemi,screen);
break;
x+=xvel;
apply_surface(x,y,ennemi,screen);
break;
x-=xvel;
apply_surface(x,y,ennemi,screen);
break;
x-=xvel;
apply_surface(x,y,ennemi,screen);
break;
x-=xvel;
apply_surface(x,y,ennemi,screen);
break;
}
SDL_Delay(4000);
}
while(1) { break; x+=xvel; apply_surface(x,y,ennemi,screen);
This will enter the loop at while(1)
, then exit the loop immediately at the first break
without running any other code.
I don’t know what apply_surface
looks like, but does it call SDL_Flip()
or SDL_UpdateRect()
? It looks like there should be at least one thing drawn to the screen, presuming IMG_Load
succeeded.
Apply surface displays the “enemy” image on the screen.
After removing the "break"s this error appears :
"undefined reference to `apply_surface’ " which i didn’t understand the error because i’m sure that the arguments of this function are true .
“Undefined reference” means the function wasn’t found at link time…make sure the source file with apply_surface
is built with everything else.