记录一些学习心得
1 when you use SDL lib at first,you must initialize it.example code:
if(SDL_Init(SDL_INIT_VIDEO)<0){
fprintf(stderr,"don't error init sdl:%s/n",SDL_GetError());
exit(1);
}
atexit(SDL_Quit);
SDL_INIT_VIDEO initializes the video subsystem
SDL_INIT_AUDIO initializes the audio subsystem
SDL_INIT_TIMER initializes the time subsystem
SDL_INIT_JOYSTICK initializes the joystick subsystem joystick:操作杆
SDL_INIT_EVERYTHING initializes all of above
2
SDL_Surface *tmp;
tmp=IMG_Load("image/gameover.png"); //导入一张PNG图片
SDL_SetColorKey(tmp,SDL_SRCCOLORKEY,SDL_MapRGB(tmp->format,255,0,255)); //将游戏图片中RGB为255,0,255的颜色变为transparent pixel.
tmp=SDL_DisplayFormat(tmp); //convert a surface to the display format
3 load a picture,you can use IMG_Load function to load a picture for png format. code like:
Surface *backgroud; // declares a Surface variable backgroud;
background=IMG_Load("image/background.png"); //load a png picture
SDL_SetColorKey(ge->background,SDL_SRCCOLORKEY,SDL_MapRGB(ge->background->format,255,0,255));
background=SDL_DisplayFormat(ge->background);
or uses SDL_LoadBMP function
image = SDL_LoadBMP(file);
if ( image == NULL ) {
fprintf(stderr, "无法加载 %s: %s/n", file, SDL_GetError());
return;
}
4 about SDL_rect.
you can declare a SDL_rect variable,but don't declare a SDL_rect pointer,i don't know why,who can tell me why to do. when i do like do this
SDL_rect *dest;
dest->x=100; // complie code,run, a error at the line.
1 when you use SDL lib at first,you must initialize it.example code:
if(SDL_Init(SDL_INIT_VIDEO)<0){
fprintf(stderr,"don't error init sdl:%s/n",SDL_GetError());
exit(1);
}
atexit(SDL_Quit);
SDL_INIT_VIDEO initializes the video subsystem
SDL_INIT_AUDIO initializes the audio subsystem
SDL_INIT_TIMER initializes the time subsystem
SDL_INIT_JOYSTICK initializes the joystick subsystem joystick:操作杆
SDL_INIT_EVERYTHING initializes all of above
2
SDL_Surface *tmp;
tmp=IMG_Load("image/gameover.png"); //导入一张PNG图片
SDL_SetColorKey(tmp,SDL_SRCCOLORKEY,SDL_MapRGB(tmp->format,255,0,255)); //将游戏图片中RGB为255,0,255的颜色变为transparent pixel.
tmp=SDL_DisplayFormat(tmp); //convert a surface to the display format
3 load a picture,you can use IMG_Load function to load a picture for png format. code like:
Surface *backgroud; // declares a Surface variable backgroud;
background=IMG_Load("image/background.png"); //load a png picture
SDL_SetColorKey(ge->background,SDL_SRCCOLORKEY,SDL_MapRGB(ge->background->format,255,0,255));
background=SDL_DisplayFormat(ge->background);
or uses SDL_LoadBMP function
image = SDL_LoadBMP(file);
if ( image == NULL ) {
fprintf(stderr, "无法加载 %s: %s/n", file, SDL_GetError());
return;
}
4 about SDL_rect.
you can declare a SDL_rect variable,but don't declare a SDL_rect pointer,i don't know why,who can tell me why to do. when i do like do this
SDL_rect *dest;
dest->x=100; // complie code,run, a error at the line.

本文记录了使用SDL库的学习心得,包括初始化SDL库的不同子系统,如视频、音频、定时器等;介绍了导入PNG图片、设置颜色键及转换显示格式的方法;还提及加载图片的不同函数,以及使用SDL_rect变量时遇到的问题。
6057

被折叠的 条评论
为什么被折叠?



