3

I am currently working on a project that I built using the alpha C4 framework.

I am trying to make start an animation as soon as the app launches without having to use an type of interaction to get it going (i.e. touchesBegan)...

But unfortunately I cant figure it out.

C4 - Travis
  • 4,502
  • 4
  • 31
  • 56
M.Ermecheo
  • 87
  • 1
  • 8

1 Answers1

2

In C4, the way to do this is to take advantage of the following method:

-(void)performSelector:withObject:afterDelay:

And, for the current version of C4, the best way to use this is like:

#import "C4WorkSpace.h"

@interface C4WorkSpace ()
-(void)methodToRunImmediately;
@end

@implementation C4WorkSpace {
    C4Shape *circle;
}

-(void)setup {
    circle = [C4Shape ellipse:CGRectMake(100, 100, 100, 100)];
    [self.canvas addShape:circle];
    [self performSelector:@selector(methodToRunImmediately) withObject:nil afterDelay:0.1];
}

-(void)methodToRunImmediately {
    circle.animationDuration = 1.0f;
    circle.animationOptions = AUTOREVERSE | REPEAT;
    circle.center = CGPointMake(384, 512);
}
@end

This code will start your animations after a 1/10th of a second delay... which will look immediate.


The answer above was posted a long time ago, and we were able to implement a more simple approach for this that doesn't require knowing what selectors are. The code above can now be run with the following:

-(void)runMethod:afterDelay:

Such that, in C4, the original line:

[self performSelector:@selector(methodToRunImmediately) 
           withObject:nil 
           afterDelay:0.1];

... can be rewritten as:

[self runMethod:@"methodToRunImmediately" afterDelay:0.1];
C4 - Travis
  • 4,502
  • 4
  • 31
  • 56