Using CGContext to display a sprite sheet iPhone

Posted by Mike on Stack Overflow See other posts from Stack Overflow or by Mike
Published on 2010-05-19T07:38:02Z Indexed on 2010/05/19 7:40 UTC
Read the original article Hit count: 407

Filed under:
|
|
|

Hello,

So I have a spritesheet in png format, and have already worked out the coordinates for what I want to display. I'm trying to create a method that will return a UIImage when passed the location information on the spritesheet. I'm just not sure how to use the CGContext stuff along with the the coordinates to return an UIImage.

I was looking to CGContextClipToRect because I think that is the way to do it, but I just can't seem to get it to work.

Something like this

CGSize size = CGSizeMake(xSize, ySize);
UIGraphicsBeginImageContext(size);
//CGContextClipToRect(spriteSheet.size, imageRect);
[spriteSheet drawAtPoint:CGPointMake(xPos, yPos)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return scaledImage;

returns only what is in the size Context. I need to be able to "move" this size window around the spritesheet if that makes sense.

Any help would be appreciated.

Thanks, Mike

© Stack Overflow or respective owner

Related posts about iphone

Related posts about cgcontext