Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I definitely would roll my own system in this case, and the performance loss versus using built-in animation code can be minimized using <code>CADisplayLink</code> rather than <code>NSTimer</code> (<code>CADisplayLink</code> is directly tied to the on-screen updates timer). </p> <p>The fact that you have 20 clouds simultaneously doesn't really change things too much, as I presume your intention is to animate those 20 clouds separately using the built in animations already.</p> <p>If you're unsure of how big of a performance hit it will have on things in the end, you could try simply adding a bunch of clouds (50 or so) using the built in animation and see how sluggish they move, then switching it out to built-in animation code and comparing.</p> <p>Edit: this discussion on Stack Overflow goes into detail on how to do what you're asking, in case you go that route: <a href="https://stackoverflow.com/questions/554997/cancel-a-uiview-animation">Cancel a UIView animation?</a></p> <p>Example:</p> <pre><code>// startAnimating called once to initiate animation loop. might be stopped e.g. // if game is paused or such - (void)startAnimating { // displayLink = the CADisplayLink for the current animation, if any. if (displayLink) { [displayLink invalidate]; [displayLink release]; } displayLink = [[CADisplayLink displayLinkWithTarget:self selector:@selector(animationTick:)] retain]; [displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; } // tick method is called at every interval; we want to update things based on // a delta time (duration), so that if things get bogged down and the updates // come less often, we don't go into slow motion - (void)tick:(CADisplayLink *)sender { CFTimeInterval duration = sender.duration; // here, we update the position for all the UIView objects. example: CGRect cloudFrame; for (UIView *cloud in clouds) { cloudFrame = cloud.frame; cloudFrame.origin.x += windForceX * duration; cloudFrame.origin.y += windForceY * duration; cloud.frame = cloudFrame; } // here we might update the windForceX and Y values or this might happen somewhere // else } </code></pre>
 

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