Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 05-05-2009, 05:11 PM   #1 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 96
Austin is on a distinguished road
Default How do you animate a sprite sheet?

I know how to animate individual .png's but how would you take one png (spritesheet) and then animate it?

Last edited by Austin; 05-12-2009 at 10:39 PM.
Austin is offline   Reply With Quote
Old 05-12-2009, 10:39 PM   #2 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 96
Austin is on a distinguished road
Default

anyone?
Austin is offline   Reply With Quote
Old 05-12-2009, 11:13 PM   #3 (permalink)
Registered Member
 
Join Date: Jan 2009
Location: San Diego, CA
Posts: 406
jtara is on a distinguished road
Default

Maybe they don't know what you are asking?
jtara is offline   Reply With Quote
Old 05-12-2009, 11:29 PM   #4 (permalink)
New Member
 
Join Date: May 2009
Location: Los Angeles, CA
Posts: 15
Upsidedowndog is on a distinguished road
Default

Quote:
Originally Posted by jtara View Post
Maybe they don't know what you are asking?
I think I can clarify this - I used to use Sprite Sheets all the time in games years ago, and they're commonly used in console games. Basically it's a single graphic made up of a grid. Each box of the grid contains one state of a graphic sprite or an animation frame, say all the possible states of a character walking. In order to animate this, the graphic is either masked in the view and its top-left coordinate changed to match the top-left coordinate of the appropriate grid box so that the image in that box appears within the masked area, or the area of a particular box in the grid is copied to a new bitmap and displayed itself.

I am actually planning on using this technique for a current project, but haven't yet gotten the module built, so as much of an explanation as I can provide, I'm actually no help right now! Sorry!
Upsidedowndog is offline   Reply With Quote
Old 05-13-2009, 12:23 AM   #5 (permalink)
Registered Member
 
Join Date: May 2009
Location: Singapore
Posts: 91
gibtang is on a distinguished road
Default

Quote:
Originally Posted by Austin View Post
anyone?
This is how I do it
1 - Use CGRectMake to make a rect (The area where I want to draw 1 sprite from the sprite sheet)
2 - Use CGContextSaveGState to save the current context
3 - Use CGContextClipToRect to clip the context to the rect in #1
4 - Use drawAtPoint to draw my UIImage
__________________
Try out my latest game Piecehunters Lite for free

Else get the paid version for $1.99 cents and you can bring your progress from the lite version over to the premium version
gibtang is offline   Reply With Quote
Old 05-13-2009, 12:31 AM   #6 (permalink)
Registered Member
 
Join Date: May 2009
Location: Singapore
Posts: 91
gibtang is on a distinguished road
Default

It is best that you play around with the X,Y coordinates so that you can see how the clipping works

Last edited by gibtang; 05-13-2009 at 12:32 AM. Reason: change text
gibtang is offline   Reply With Quote
Old 05-13-2009, 01:07 AM   #7 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 96
Austin is on a distinguished road
Default

Quote:
Originally Posted by gibtang View Post
This is how I do it
1 - Use CGRectMake to make a rect (The area where I want to draw 1 sprite from the sprite sheet)
2 - Use CGContextSaveGState to save the current context
3 - Use CGContextClipToRect to clip the context to the rect in #1
4 - Use drawAtPoint to draw my UIImage
Thanks for the help! I knew there was a way to do this.
Austin is offline   Reply With Quote
Old 05-13-2009, 01:26 AM   #8 (permalink)
Registered Member
 
Join Date: May 2009
Location: Singapore
Posts: 91
gibtang is on a distinguished road
Default

Quote:
Originally Posted by Austin View Post
Thanks for the help! I knew there was a way to do this.
No problem, sprite sheet and sprite clipping was what I used a long time ago when I was doing J2ME mobile game dev when space was at a premium, but with iPhone. I have pretty much abandoned it and just put in 1 sprite per UIImage. It makes coding a lot easier for me.
__________________
Try out my latest game Piecehunters Lite for free

Else get the paid version for $1.99 cents and you can bring your progress from the lite version over to the premium version
gibtang is offline   Reply With Quote
Old 05-13-2009, 06:32 PM   #9 (permalink)
Registered Member
 
Join Date: Apr 2009
Posts: 96
Austin is on a distinguished road
Default

This is more difficult than I thought. I'm trying to crop the image using CGRectMake, here is my code...

Code:
UIImage *spriteImage = [UIImage imageNamed:@"spritesheet.png"];
	
sprite.image = spriteImage;	
	
sprite.frame = CGRectMake(110.0, 180.0, 100.0, 100.0);
Austin is offline   Reply With Quote
Reply

Bookmarks

Tags
sprite

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 319
8 members and 311 guests
blueorb, givensur, guusleijsten, jbro, mer10, n00b, SLIC, yomo710
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,649
Threads: 94,113
Posts: 402,880
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Anwerbl
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 09:04 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0