Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6764011
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:32:39+00:00 2026-05-26T14:32:39+00:00

I want to separate the game logic and the rendering into two different loops,

  • 0

I want to separate the game logic and the rendering into two different loops, because I don’t want the fps to control the game speed. I tried to achieve this by creating a CADisplayLink for the rendering, and an NSTimer for the game logic. But then a strange thing happened:

Sometimes (1 out of 15 application runs) the game runs on a very low fps (about 5-10), but the rest of the times it’s completely smooth. If I remove the game logic’s NSTimer and combine the two loops the fps is consistently high, but it’s obviously not an acceptable solution. So it looks like that sometimes the two timers ‘delaying each other’ or something like that, but I don’t completely understand the inner working of runloops.

Here’s how I create the timer and the displaylink:

NSTimer *gameTimer = [[NSTimer alloc] initWithFireDate:[NSDate date] interval:1.0 / 60.0 target:self selector:@selector(gameTimerFired:) userInfo:nil repeats:YES];
[[NSRunLoop mainRunLoop] addTimer:gameTimer forMode:NSDefaultRunLoopMode];
[gameTimer release];

CADisplayLink *aDisplayLink = [[UIScreen mainScreen] displayLinkWithTarget:self selector:@selector(drawFrame)];
[aDisplayLink setFrameInterval:animationFrameInterval];
[aDisplayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
self.displayLink = aDisplayLink;

Can you tell me what causes the fps issue and how to fix it?

Or can you recommend any other solutions to separate the rendering and the game logic loop?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T14:32:39+00:00Added an answer on May 26, 2026 at 2:32 pm

    You can do this with one loop using either your gameTimer or the CADisplayLink by measuring the time passed since the last loop and using it to augment your game logic.

    So..

    NSDate *oldTime = [[NSDate date] retain];
    
    -(void)updateGame {
        NSDate *curTime = [NSDate date];
        NSTimeInterval timePassed_ms = [curTime timeIntervalSinceDate:oldTime] * 1000.0;
    
        [oldTime release];
        oldTime = curTime;
        [oldTime retain];
    
        //use the timePassed_ms to augment your game logic.  IE: Moving a ship
        [ship moveLength:ship.velocity * timePassed_ms/1000.0];
    }
    

    That’s usually the way I handle this sort of stuff. I usually like to build update functions right into my game objects. So updating the ship would actually look like this:

    [ship update:timePassed_mc];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What if you don't want to start a separate project for grails but instead
'm developing a 2D game and I want separate the game engine from the
I have the simplest code that I want to separate in three files: Header
I know that with a large site you would want to separate footers, menus,
I have a web application that is becoming rather large. I want to separate
I want to create separate folders for my layouts, like this in my resource
I want to create 2 separate pickers in the same view using the same
I want to create a separate thread that runs its own window. Frankly, the
I want to keep SSH debug info separate (and logged) from other input. However,
I want to use CSS sprites on a web site instead of separate image

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.