|
| ||||||||||||||||
SDL_Surface *img x = 2 * (画像サイズ); y = 1 * (画像サイズ); w = 画像サイズ;h = 画像サイズ; |
SDL_Surface *screen dx = 張りたい場所のx座標; dy = 張りたい場所のy座標; |
DrawImg.cppのソース#ifndef __DRAWIMG_H__ #define __DRAWIMG_H__ void InitImg(void); //画像の読み込み void DrawImg(int x,int y,int w,int h,int dx,int dy); //画像の描画 void EndImg(void); //画像の破棄 #endif
#define __DRAWIMG_CPP__ #include "Def.h" SDL_Surface *img; void InitImg() //画像の読み込み { img = IMG_Load("sample.png"); } void DrawImg(int x,int y,int w,int h,int dx,int dy) //引数に、画像内の目的の画像の座標と大きさ、 { //貼り付け位置の座標を指定する。 SDL_Rect src; src.x=x;src.y=y; src.w=w;src.h=h; SDL_Rect draw; draw.x=dx;draw.y=dy; SDL_BlitSurface(img,&src,screen,&draw); //これで、どこから呼び出されても、同じ処理で済む。 } void EndImg() { SDL_FreeSurface(img); }