Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 11-20-2011, 08:14 PM   #1 (permalink)
Registered Member
 
Join Date: Aug 2011
Posts: 245
samurle is on a distinguished road
Question Game Loop with CADisplayLink

I have a very simple game loop driven by CADisplayLink. It basically moves a single UIImageView
across screen at a constant rate by updating its position. However, the movement is somewhat jerky.

I'm using the default FrameInterval value of 1 for 60fps. And the image does use transparency.

Just wondering what I can do to improve it. Changing the project to release mode doesn't help.

I tried using a constant delta time of 1/60, and also tried calculating my own delta time,
but that doesn't seem to help either. It doesn't make any difference.

Code:
 displayLink = [NSClassFromString(@"CADisplayLink") displayLinkWithTarget:self selector:@selector(myGameLoop:)];
 [displayLink setFrameInterval:1];
 [displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];

-(void)myGameLoop {

 for(Piece *piece in self.pieces) {
   float speed = dt * piece.speed;
   piece.center += CGPointMake( dx * speed, dy * speed );
 }
}
Any suggestions?
samurle is offline   Reply With Quote
Old 11-20-2011, 08:22 PM   #2 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by samurle View Post
I have a very simple game loop driven by CADisplayLink. It basically moves a single UIImageView
across screen at a constant rate by updating its position. However, the movement is somewhat jerky.

I'm using the default FrameInterval value of 1 for 60fps. And the image does use transparency.

Just wondering what I can do to improve it. Changing the project to release mode doesn't help.

I tried using a constant delta time of 1/60, and also tried calculating my own delta time,
but that doesn't seem to help either. It doesn't make any difference.

Code:
 displayLink = [NSClassFromString(@"CADisplayLink") displayLinkWithTarget:self selector:@selector(myGameLoop:)];
 [displayLink setFrameInterval:1];
 [displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];

-(void)myGameLoop {

 for(Piece *piece in self.pieces) {
   float speed = dt * piece.speed;
   piece.center += CGPointMake( dx * speed, dy * speed );
 }
}
Any suggestions?
Use a completely different approach. Re-rendering a view by moving it's location for every frame does not make good use of the graphics hardware.

For view-based animation, you should use Core Animation, and let the system do the rendering.

For frame-based animation like you're trying to do, use OpenGL or a framework like Cocos2D.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is online now   Reply With Quote
Old 11-20-2011, 08:35 PM   #3 (permalink)
Registered Member
 
Join Date: Aug 2011
Posts: 245
samurle is on a distinguished road
Question

Quote:
Originally Posted by Duncan C View Post
Use a completely different approach. Re-rendering a view by moving it's location for every frame does not make good use of the graphics hardware.

For view-based animation, you should use Core Animation, and let the system do the rendering.

For frame-based animation like you're trying to do, use OpenGL or a framework like Cocos2D.
Thanks, what type of timing mechanism does Cocos2D use? I see it has a class called CCScheduler.h,
but I'm not sure how it gets fired.

I don't see any mention of CADisplayLink or NSTimer.
Then again, I think it does use CADisplayLink too.

Last edited by samurle; 11-20-2011 at 08:40 PM.
samurle is offline   Reply With Quote
Old 11-20-2011, 08:42 PM   #4 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by samurle View Post
Thanks, what type of timing mechanism does Cocos2D use? I see it has a class called CCScheduler.h,
but I'm not sure how it gets fired.

I don't see any mention of CADisplayLink or NSTimer.
Then again, I think it does use CADisplayLink too.
No idea. Never used it.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is online now   Reply With Quote
Reply

Bookmarks

Tags
cadisplaylink

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 391
15 members and 376 guests
7twenty7, chiataytuday, Clouds, dedeys78, Duncan C, e2applets, EvilElf, iekei, ipodphone, jeroenkeij, leostc, matador1978, mbadegree, Murphy, QuantumDoja
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,676
Threads: 94,125
Posts: 402,910
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jleannex55
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 06:32 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0