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 06-01-2009, 02:46 AM   #1 (permalink)
New Member
 
Join Date: May 2009
Location: Beijing, CN
Posts: 23
Send a message via MSN to iwind Send a message via Skype™ to iwind
Default How can i set delay for each frame in an animation?

I am using cocos2d library, and now i have a question, how can i set delay for each frame in an animation? In cocos2d, you can only set a duration on animation, but i want to let different frame stay different time, for instance,
frame1 stay 0.1 second
frame2 stay 0.2 second
frame3 stay 0.15 second

How can i do this?

Another question, can the frame be a sprite? Because i want to add more than one images to each frame.

Thanks for help advanced.
iwind is offline   Reply With Quote
Old 06-01-2009, 03:18 AM   #2 (permalink)
Registered Member
 
Join Date: May 2009
Posts: 97
Default

hi
I would go for a system like this

1) store the delay you want to apply (I would put in the detail of you custom frame)
2)do a for(MyCustomView *inst in TheCollectionThatGroupsMyListOfElement)
in which you can happely launch a timer that will animate you View and set the delay of the timer to the value stored in you custom view

Timer Programming Topics for Cocoa: Using Timers

I don't know what you mean by sprite ut if you mean a composed view (icon + text + another iamge etc

then just create a custom UIView in wich you build your custom display

i did like that to create a image with some text underneath

hope it helped

jason
__________________
We all have to go down this same road.
You liked it when the ones in front of you helped.
So think about the ones behind you.
---
try, try again, try some more, then ask.
once you asked, continue trying until you find a solution.
and finally make sure you post the solution.
Jason Rogers is offline   Reply With Quote
Old 06-01-2009, 04:30 AM   #3 (permalink)
New Member
 
Join Date: May 2009
Location: Beijing, CN
Posts: 23
Send a message via MSN to iwind Send a message via Skype™ to iwind
Default

Quote:
Originally Posted by Jason Rogers View Post
hi
I would go for a system like this

1) store the delay you want to apply (I would put in the detail of you custom frame)
2)do a for(MyCustomView *inst in TheCollectionThatGroupsMyListOfElement)
in which you can happely launch a timer that will animate you View and set the delay of the timer to the value stored in you custom view

Timer Programming Topics for Cocoa: Using Timers

I don't know what you mean by sprite ut if you mean a composed view (icon + text + another iamge etc

then just create a custom UIView in wich you build your custom display

i did like that to create a image with some text underneath

hope it helped

jason
Thank you for help. The "sprite" is a word in cocos2d library, you can check it out here:
cocos2d-iphone - Google Code

A sprite can flip, scale, move and do other actions, and it can have some children(other sprites).

I want to use the library to improve my development process, it seems that i need to implement sprite animation myself.But i just think if there is a way to do it with cocos2d Animation class.

NSTimer class is helpful to me, thanks.
iwind is offline   Reply With Quote
Old 06-01-2009, 06:26 AM   #4 (permalink)
Registered Member
 
Join Date: May 2009
Posts: 97
Default

I read about coco2d really quickly (I'll need to do some opengl in in a couple of weeks so I'm reading up)

if your using coco2d as your main framework you might want to check out there version of the timer

BestPractices - cocos2d-iphone - cocos2d for iPhone best practices - Google Code

Code:
    * Try not to use Cocoa's NSTimers. Instead use cocos2d's own scheduler.
    * If you use cocos2d scheduler, you will have:
          o automatic pause/resume.
          o when the Layer (Scene, Sprite, CocosNode) enters the stage the timer will be automatically activated, and when it leaves the stage it will be automatically deactivated.
          o Your target/selector will be called with a delta time

            /**********************************************************/
            // OK OK OK OK OK
            /**********************************************************/
            -(id) init
            {
                    if( ! [super init] )
                            return nil;

                    // schedule timer
                    [self schedule: @selector(tick:)];
                    [self schedule: @selector(tick2:) interval:0.5];

                    return self;
            }

            -(void) tick: (ccTime) dt
            {
                    // bla bla bla
            }

            -(void) tick2: (ccTime) dt
            {
                    // bla bla bla
            }

            /**********************************************************/
            // BAD BAD BAD BAD
            /**********************************************************/
            // Why BAD ?
            // You can't pause the game automagically.
            -(void) onEnter
            {
                    [super onEnter];
                    timer1 = [NSTimer scheduledTimerWithTimeInterval:1/FPS target:self selector:@selector(tick1) userInfo:nil repeats:YES];
                    timer2 = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(tick2) userInfo:nil repeats:YES];
            }
            -(void) onExit
            {
                    [timer1 invalidate];
                    [timer2 invalidate];
                    [super onExit];
            }
            -(void) tick
            {
                    // bla bla bla
            }

            -(void) tick2
            {
                    // bla bla bla
            }
it seams to add a few insteresting functionalities that you need when doing 3D programing and you dont want to dig in the code to much.

otherwise as I guessed a sprite is a UIView with extra functionalities ^^
I tend at the moment to try and write the low level stuff by hand and get my own framework of classes and functions going but that a lot of work

maybe if I get round to coco2D you can help me out

best regards

jason
__________________
We all have to go down this same road.
You liked it when the ones in front of you helped.
So think about the ones behind you.
---
try, try again, try some more, then ask.
once you asked, continue trying until you find a solution.
and finally make sure you post the solution.
Jason Rogers is offline   Reply With Quote
Old 06-01-2009, 09:53 AM   #5 (permalink)
New Member
 
Join Date: May 2009
Location: Beijing, CN
Posts: 23
Send a message via MSN to iwind Send a message via Skype™ to iwind
Default

The schedule and unschedule only work on classes who inherited from CocosNode, that make me very sad, even my own class interface inherited CocosNode:

Code:
@interface KAnimation : CocosNode {

}
@end
then i try to schedule a selector like this:
Code:
[self schedule:@selector(_playFrame:) interval:1];
Build and run the application, i found the selector _playFrame: never be called.

I think cocos2d framework still need to be improved for more easy-to-use.
iwind is offline   Reply With Quote
Old 02-08-2010, 12:32 AM   #6 (permalink)
Registered Member
 
Join Date: Aug 2009
Posts: 125
Default

how to animate a sequence in sprite sheet lets say 1 image is at 0,100 and other is at 10,100 in same sprite sheet
rahul7star is offline   Reply With Quote
Reply

Bookmarks

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,353
Threads: 39,148
Posts: 171,625
Top Poster: smasher (2,577)
Welcome to our newest member, pyrrho
Powered by vBadvanced CMPS v3.1.0

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