0

I want to use CADisplayLink instead of NSTimer for an animation of a ball which is just moving, but with CADisplayLink it doesn't work. What could be the problem in the following code?

#import "UntitledViewController.h"


@implementation UntitledViewController
@synthesize maBalle;


-(void) update:(CADisplayLink*)displayLink {
}

-(void)topHorloge {
    maBalle.center =CGPointMake(maBalle.center.x+coordonnees.x,maBalle.center.y+coordonnees.y);
    if((maBalle.center.x)-20 <0 || (maBalle.center.x)+20 >320)
        coordonnees.x=-coordonnees.x;
    if((maBalle.center.y)-20 <0 || (maBalle.center.y)+20 >460)
        coordonnees.y=-coordonnees.y;
}

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
    displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(renderAndUpdate)];
    [displayLink setFrameInterval:2];
    [displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];


}
Brad Larson
  • 170,088
  • 45
  • 397
  • 571
arvin Arabi
  • 253
  • 1
  • 7
  • 21
  • You need to format all of the code or you may not get an answer anytime soon **{}** – Joe Jan 26 '11 at 19:34
  • As hotpaw2 indicates, you're missing chunks of code in your sample here. Where is your `-renderAndUpdate` method that handles the CADisplayLink callback? – Brad Larson Jan 26 '11 at 21:21

1 Answers1

1

Where is your renderAndUpdate handler? (which you specified as your displaylink callback)

hotpaw2
  • 70,107
  • 14
  • 90
  • 153
  • no renderAnUpdate is topHorloge. But now it work. but another problem is that when I use CADisplayLink first it's 60fps but after 2 second it's 40fps. What can I do to solve this problem ? – arvin Arabi Feb 03 '11 at 19:42