【问题标题】:Why isn't CADisplayLink working in this case?为什么 CADisplayLink 在这种情况下不起作用?
【发布时间】:2011-01-26 19:06:00
【问题描述】:

我想使用 CADisplayLink 而不是 NSTimer 来制作一个正在移动的球的动画,但是使用 CADisplayLink 它不起作用。下面的代码可能是什么问题?

#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];


}

【问题讨论】:

  • 您需要格式化所有代码,否则您可能不会很快得到答案{}
  • 正如 hotpaw2 所指出的,您在此处的示例中缺少大量代码。处理 CADisplayLink 回调的 -renderAndUpdate 方法在哪里?

标签: iphone cocoa-touch cadisplaylink


【解决方案1】:

您的 renderAndUpdate 处理程序在哪里? (您指定为 displaylink 回调)

【讨论】:

  • 没有 renderAnUpdate 是 topHorloge。但现在它起作用了。但另一个问题是,当我首先使用 CADisplayLink 时,它是 60fps,但在 2 秒后它是 40fps。我该怎么做才能解决这个问题?
猜你喜欢
  • 2017-11-26
  • 2010-12-29
  • 1970-01-01
  • 2021-08-05
  • 2011-11-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多