c# - How to load sprite sheets that clamp to the sprite, excluding the background? -


i'm having lot of trouble googling because don't know terminology it. has common problem though. want iterate through sprite sheet, want ignore transparent background around sprite , not include part of what's displayed.

for example, if have few frames, want iterate through each frame , load image. then, in frame, want narrow down drawing rectangle around image itself, not "background". accomplished finding corners of sprite non-transparent pixels (not sure how part works).

does make sense? again, not sure words use here...let me know if unclear.

the goal here loading sprites square other frames, won't wobble or bounce unintentionally.

thanks much!!

i working on first game , had similar problem transparent areas around sprites, in case collisions.

what did set each sprite has position, height, width , padding x , y.

vector2 position = new vector2(100,100); int frameheight = 48; int framewidth = 48; int paddingx = 4; int paddingy = 3; 

with info can need, instance rectangle represents bounding box around sprite can use:

boundingrectangle = new rectangle(   (int)position.x + paddingx,    (int)position.y + paddingy,    framewidth - (paddingx * 2),    frameheight - (paddingy * 2)); 

i read in xna 4.0 game development example kurt jaegers (which has been ton of me)


Comments