SDL_GetKeyState();
Uint8 *keys=SDL_GetKeyState(NULL);
if( keys[SDLK_UP] ) printf("↑が押されています。");
#include <stdio.h> #include "SDL/SDL.h" #include "SDL/SDL_image.h" #pragma comment(lib, "SDL.lib") #pragma comment(lib, "SDLmain.lib") #pragma comment(lib, "SDL_image.lib") bool Init(void); //初期処理 bool Event(void); //イベント処理 void End(void); //終了処理 void Anime(void); //アニメ処理用 SDL_Surface *screen; SDL_Surface *img1; SDL_Surface *img2; int main(int argc, char* argv[]) { if(!Init()) //初期化&確認 { printf("初期化に失敗しました"); return 0; } img1 = IMG_Load("sample1.png"); img2 = IMG_Load("sample2.png"); while(1) //メインループ { Anime(); //アニメ処理へ SDL_Flip(screen); if(!Event()) break; //イベント確認 SDL_Delay(60); //休憩。(アニメの動作が遅ければ、ここの数字を減らす) } SDL_FreeSurface(screen); //SDL_Surface型変数の中身を消去する。 SDL_FreeSurface(img1); SDL_FreeSurface(img2); End(); //終了処理へ return 0; } void Anime() { SDL_Rect rect; rect.x=0;rect.y=0; rect.w=640;rect.h=480; Uint8 *keys=SDL_GetKeyState(NULL); if(keys[SDLK_UP]) { SDL_BlitSurface(img1,NULL,screen,&rect); //UPキーが押されていたらimg1をscreenに転送 }else{ SDL_BlitSurface(img2,NULL,screen,&rect); //UPキーが押されていなければimg2をscreenに転送 } } ・・・以下省略・・・