Note that there are some explanatory texts on larger screens.

plurals
  1. POHow many times a second should CADisplayLink's displayLink be called?
    primarykey
    data
    text
    <p>I have a <code>CADisplayLink</code> running in line with Chipmunk Physics, and I'm getting very slow performance. I put an <code>NSLog</code> in the method that's called on the <code>CADisplayLink</code> update, and it's being called an average of 22 times per second. I was under the impression that that should be nearer 60. I have the <code>frameInterval</code> set to 1, so should it be 60fps, in a perfect world? The delta times are averaging around 0.0167 seconds (and 1 / 60 IS 0.0167, which is confusing me even further).</p> <p>I just have four walls around the bounds of my screen and just eight circle-shaped bodies on-screen, updating to <code>UIButton</code> instances on each call, so I don't think I'm doing anything that should tax it to this extent on both my 4S and iPad3. I'm applying a random force to each button once every 2.5 seconds in a separate method. Running in the simulator is butter-smooth, so it's a device-only issue. Can anyone help me spot what's causing the slowdown here, and what I can do about it?</p> <p>Here's the relevant code, first that which sets up the link:</p> <pre><code>[NSTimer scheduledTimerWithTimeInterval: 2.5f target: self selector: @selector(updateForces) userInfo: nil repeats: YES]; _displayLink = [CADisplayLink displayLinkWithTarget: self selector: @selector(update)]; _displayLink.frameInterval = 1; [_displayLink addToRunLoop: [NSRunLoop mainRunLoop] forMode: NSRunLoopCommonModes]; </code></pre> <p>Here's the method that should be called (I think!) 60 times per second, but is called only 22 or so:</p> <pre><code>if (!gameIsPaused) { cpFloat dt = _displayLink.duration * _displayLink.frameInterval; cpSpaceStep([[AGChipmunkSpace sharedInstance] space], dt); for (LCBall *i in balls) { cpVect pos1 = cpBodyGetPos(i.body); CGAffineTransform trans1 = CGAffineTransformMakeTranslation(pos1.x, pos1.y); CGAffineTransform rot1 = CGAffineTransformMakeRotation(cpBodyGetAngle(i.body)); i.button.transform = CGAffineTransformConcat(rot1, trans1); } } </code></pre> <p>And finally, here's the method that's called every 2.5 seconds, to apply the random forces (updateForces):</p> <pre><code>if (!gameIsPaused) { for (LCBall *i in balls) { int randomAngle = arc4random() % 360; CGPoint point1 = [self getVectorFromAngle: randomAngle AndMagnitude: (arc4random() % 40) + ((arc4random() % 20) + 15)]; i.body -&gt; f = cpv(point1.x, point1.y); } } </code></pre> <p>(Also, here's my method to get a vector from an angle, which I doubt is causing the issue):</p> <pre><code>angle = (angle / 180.0) * M_PI; float x = magnitude * cos(angle); float y = magnitude * sin(angle); CGPoint point = CGPointMake(x, y); return point; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload