views:

459

answers:

1

I am making a simple app in which filled circles bounce around the screen. Right now, the speed of the circles is fixed, but I want them to speed up or slow down randomly.

I originally tried to use NSTimer, but I discovered that the time interval could not be made irregular. According to Apple's documentation, with the NSAnimation class, "Unlike NSTimer, animation notifications can occur at irregular intervals, allowing you to create animations that appear to speed up or slow down."

So it appears I should use the NSAnimation class. However, when I looked at the drawing process in NSAnimation, it seems to be bulky and limited. I want to make several circles and define parameters for their behavior, so I would much prefer to use a simpler framework such as cocos2d-iphone.

Can I use cocos2d's scheduler to make irregular intervals? Or must I use NSAnimation?

The cocos2d scheduler looks like this:

-(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
}
A: 

Instead of making the timer delay change, how about having a constant timer interval (say 20 Hz) and changing the movement delta instead?

Daniel Dickison
What is the movement delta? I already have random movement, I want random speed.
Evelyn
Oh I get it! Thanks. :)
Evelyn