Created
July 27, 2012 01:58
-
-
Save Twinklebear/3185765 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SDL_RenderCopy(rend, tex, NULL, &pos); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void ApplySurface(int x, int y, SDL_Texture *tex, SDL_Renderer *rend, SDL_Rect *clip = NULL){ | |
SDL_Rect pos; | |
pos.x = x; | |
pos.y = y; | |
//Detect if we should use clip width settings or texture width | |
if (clip != NULL){ | |
pos.w = clip->w; | |
pos.h = clip->h; | |
} | |
else { | |
SDL_QueryTexture(tex, NULL, NULL, &pos.w, &pos.h); | |
} | |
SDL_RenderCopy(rend, tex, clip, &pos); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//iW and iH are the desired clip width and height | |
int iW = 100, iH = 100; | |
SDL_Rect clips[4]; | |
//We use a for loop this time to setup our clips | |
int column = 0; | |
for (int i = 0; i < 4; ++i){ | |
if (i != 0 && i % 2 == 0) | |
++column; | |
clips[i].x = column * iW; | |
clips[i].y = i % 2 * iH; | |
clips[i].w = iW; | |
clips[i].h = iH; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Specify a default clip to start with | |
int useClip = 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//If user presses any key | |
if (e.type == SDL_KEYDOWN){ | |
switch (e.key.keysym.sym){ | |
case SDLK_1: | |
useClip = 0; | |
break; | |
case SDLK_2: | |
useClip = 1; | |
break; | |
case SDLK_3: | |
useClip = 2; | |
break; | |
case SDLK_4: | |
useClip = 3; | |
break; | |
//For quitting, escape key | |
case SDLK_ESCAPE: | |
quit = true; | |
break; | |
default: | |
break; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ApplySurface(x, y, image, renderer, &clips[useClip]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment