为什么 CADisplayLink 在这种情况下不起作用?
我想使用 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];
}
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];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的 renderAndUpdate 处理程序在哪里? (您指定为显示链接回调)
Where is your renderAndUpdate handler? (which you specified as your displaylink callback)