Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SDL_Rect map::clipToViewport(int x, int y, SDL_Rect tclip) {
- int xClip = 0;
- int yClip = 0;
- int wClip = 0;
- int hClip = 0;
- //SDL_Rect tclip;
- //tclip.x = 0;
- //tclip.y = 0;
- //tclip.w = w;
- //tclip.h = h;
- //If this tile is clipping left side x, else right side x
- if (x < this->ViewportInfo.x) {
- xClip = this->ViewportInfo.x - x;
- tclip.x += xClip;
- tclip.w -= xClip;
- } else if (x+tclip.w > this->ViewportInfo.x+this->ViewportInfo.width) {
- wClip = (x+tclip.w) - (this->ViewportInfo.x+this->ViewportInfo.width);
- tclip.w -= wClip;
- }
- //If this tile is clipping top side y, else bottom side y
- if (y < this->ViewportInfo.y) {
- yClip = this->ViewportInfo.y - y;
- tclip.y += yClip;
- tclip.h -= yClip;
- } else if (y+tclip.h > this->ViewportInfo.y+this->ViewportInfo.height) {
- hClip = (y+tclip.h) - (this->ViewportInfo.y+this->ViewportInfo.height);
- tclip.h -= hClip;
- }
- return tclip;
- }
Advertisement
Add Comment
Please, Sign In to add comment