Advertise Books Events Forum News Social Networking Support Us

sdkIQ for iPhone
($4.99)

Shape Up
($0.99)

Your First iPhone App
($1.99)

iVidCam Free
(free)

Kid Art
($0.99)

iPUBQUIZ
(£1.19)

ArtStudio
($3.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 02-07-2010, 04:06 PM   #1 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 8
Default Animate a sprite

Hi, im creating an app similar to doodle jump where my main sprite has a negative acceleration and a positive velocity whenever it touches the platforms, and i want to animate the sprite as it hits the platform, but i have no idea how to go about doing that. Can anyone give me some suggestions?
imrnm245 is offline   Reply With Quote
Old 02-07-2010, 04:25 PM   #2 (permalink)
Registered Member
 
ChrisMayer's Avatar
 
Join Date: Aug 2009
Posts: 77
Default

Assuming your sprite is a UIImageView:

Code:
myImageview.animationImages = [NSArray arrayWithObjects:[UIImage imageNamed:@"frame_1.png"],[UIImage imageNamed:@"frame_2.png"],nil];
myImageview.animationDuration=0.5;myImageview.animationRepeatCount=0;[myImageview startAnimating];
where animationDuration=0.5 is the total duration of the animation in seconds.
__________________
Recent Apps: Brain App: Math, Zombie Skydive, My Blue Screen, My Strobe Light
My Website: Chris Mayer Apps / Forum
ChrisMayer is offline   Reply With Quote
Old 02-07-2010, 04:42 PM   #3 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 8
Default

Quote:
Originally Posted by ChrisMayer View Post
Assuming your sprite is a UIImageView:

Code:
myImageview.animationImages = [NSArray arrayWithObjects:[UIImage imageNamed:@"frame_1.png"],[UIImage imageNamed:@"frame_2.png"],nil];
myImageview.animationDuration=0.5;myImageview.animationRepeatCount=0;[myImageview startAnimating];
where animationDuration=0.5 is the total duration of the animation in seconds.
i tried that, but i dont know where to declare the myImageview. Also, what would happen if my sprite wasnt a UIImageView? something like:

AtlasSpriteManager *spriteManager = (AtlasSpriteManager*)[self getChildByTag:kSpriteManager];
AtlasSprite *one = (AtlasSprite*)[spriteManager getChildByTag:kOne];
imrnm245 is offline   Reply With Quote
Old 02-07-2010, 04:47 PM   #4 (permalink)
Registered Member
 
ChrisMayer's Avatar
 
Join Date: Aug 2009
Posts: 77
Default

Ah, you're using cocos2d. Unfortunatly I've no experience with that, I usually do everything the manual way.
__________________
Recent Apps: Brain App: Math, Zombie Skydive, My Blue Screen, My Strobe Light
My Website: Chris Mayer Apps / Forum
ChrisMayer is offline   Reply With Quote
Old 02-07-2010, 10:19 PM   #5 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 8
Default

Also, in cocos2d i have a case statement to display the different platforms, but i want one of these cases to have a different value for the velocity of the sprite, so how would i go about doing that?
imrnm245 is offline   Reply With Quote
Old 02-08-2010, 12:48 AM   #6 (permalink)
Registered Member
 
Join Date: Aug 2009
Posts: 125
Default

you can use this to animate a sprite
id animation = [MoveBy actionWithDuration:2.0 position:ccp(-100, 0)]; // Make the animation MoveBy tells the sprite to move "so many pixels" from it's current position
[sprite runAction: animation]; // Tell the stickman to do the animation


though i am looking for animate a spirte sheet (having two images 1 at 0,100 and toher at 10,100)
rahul7star is offline   Reply With Quote
Old 02-08-2010, 04:42 PM   #7 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 8
Default

Those are all good answers, but thats not exactly what im looking for. Let me try it another way:

I initialized an AtlasSprite in my (id) init, which is my main sprite

Then in (void) jump, i want to take that same sprite, but i want to animate it with an array of images. The images i want to animate it with are called 2.png, 3.png, 4.png, and 5.png. Here is some code:



- (id)init {

AtlasSprite *one = [AtlasSprite spriteWithRect:CGRectMake(608,-7,60,70) spriteManager:spriteManager];
[spriteManager addChildne z:4 tag:kOne];
}


- (void)jump {
one_vel.y = 550.0f;
//This is where i want to animate "one" with an array of images called //2.png, 3.png, 4.png, and 5.png
//Also, how would i declare the atlas sprite used above in (void) jump?
}
imrnm245 is offline   Reply With Quote
Old 02-08-2010, 08:08 PM   #8 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 8
Default

i ran into another problem also. In the code below i have initialized 3 platforms, and this code works, but i want to add a special feature to the case 2 platform. I want to make an if statement saying that if my sprite touches it, the sprite's velocity will be different, but i tried all the ways i can think of and have no idea how to continue.

- (void)initPlatform {

CGRect rect;
switch(random()%3) {
case 0: rect = CGRectMake(633,83,64,13); break;
case 1: rect = CGRectMake(633,139,65,14); break;
case 2: rect = CGRectMake(725,80,78,16); break;



}
imrnm245 is offline   Reply With Quote
Old 02-08-2010, 11:38 PM   #9 (permalink)
Registered Member
 
Join Date: Aug 2009
Posts: 125
Default

try this
id anim = [[Animation alloc] initWithName:@"fight" delay:0.1];
[anim AddFrameWithName:@"goblin_swing_01"];
[anim AddFrameWithName:@"goblin_swing_01"];
[anim AddFrameWithName:@"goblin_swing_02"];
[anim AddEvent:@"something"];
[anim AddFrameWithName:@"goblin_swing_03"];
[anim AddFrameWithName:@"goblin_swing_02"];

[someSprite runAction:[Animate action:anim withDelegate:self]];
rahul7star is offline   Reply With Quote
Old 02-09-2010, 03:59 PM   #10 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 8
Default

thank you very much! That code you provided works perfectly! but i still need help with my second question...
imrnm245 is offline   Reply With Quote
Old 02-10-2010, 09:59 PM   #11 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 8
Default

Anybody know?
imrnm245 is offline   Reply With Quote
Old 02-11-2010, 11:13 PM   #12 (permalink)
Registered Member
 
Join Date: Feb 2010
Posts: 8
Default

bump
please help me, i have no clue what to do still
imrnm245 is offline   Reply With Quote
Reply

Bookmarks

Tags
animate, jump, 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


Enter the iPhone App Challenge!  Win $500!
» Advertisements
» Stats
Members: 24,292
Threads: 39,080
Posts: 171,361
Top Poster: smasher (2,575)
Welcome to our newest member, omerk
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 09:48 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0