Note that there are some explanatory texts on larger screens.

plurals
  1. PORunning multiple CADisplayLinks at a time ?
    primarykey
    data
    text
    <p>I'm using CADisplayLink as a timer for strobing. </p> <p>I have 2 CADisplayLinks:</p> <p>The main one (this runs during the whole thing):</p> <pre><code>SMPTELink = [CADisplayLink displayLinkWithTarget:self selector:@selector(onTick)]; SMPTELink.frameInterval = 1; [SMPTELink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode]; </code></pre> <p>The strobe one (this only runs when strobing occurs):</p> <pre><code>strobeLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(toggleStrobe)]; strobeLink.frameInterval = 1; [strobeLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode]; [strobeLink setPaused:YES]; // I setPaused:NO when using the strobe. </code></pre> <p>Is it bad to run two CADisplayLinks at once? Sometimes my strobe doesn't look as smooth as I think it should be. Here is my toggleStrobe method:</p> <pre><code>-(void)toggleStrobe { if (!self.firstTimestampStrobe) self.firstTimestampStrobe = strobeLink.timestamp; NSTimeInterval elapsed = (strobeLink.timestamp - self.firstTimestampStrobe); NSInteger frameNumber = (NSInteger)(elapsed * ((strobeValue*15)/255)) % 2; if (frameNumber != self.lastFrameStrobe) { if (frameNumber == 1) { UIColor *color = [[UIColor alloc] initWithRed: 0 green: 0 blue: 0 alpha: 1.0]; strobeBackground.backgroundColor = color; } else { UIColor *color = [[UIColor alloc] initWithRed: 0 green: 0 blue: 0 alpha: 0]; strobeBackground.backgroundColor = color; } self.lastFrameStrobe = frameNumber; } } </code></pre>
    singulars
    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