Game loop in objective-c




















Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Learn more. Asked 8 years, 6 months ago. Active 8 years, 4 months ago. Viewed times. Improve this question. Peteyslatts Peteyslatts 4 4 silver badges 11 11 bronze badges. Add a comment. Active Oldest Votes. Improve this answer. Simon Jordan Simon Jordan 3 3 bronze badges. Sign up or log in Sign up using Google. Loop control statements change execution from its normal sequence.

When execution leaves a scope, all automatic objects that were created in that scope are destroyed. Objective-C supports the following control statements. Terminates the loop or switch statement and transfers execution to the statement immediately following the loop or switch.

Causes the loop to skip the remainder of its body and immediately retest its condition prior to reiterating. A loop becomes infinite loop if a condition never becomes false. The for loop is traditionally used for this purpose.

Since none of the three expressions that form the for loop are required, you can make an endless loop by leaving the conditional expression empty.

UIGraphics is only thread-safe since 4. Since we are talking about games, I assumed OpenGL, where such a loop works without problems. I thought I read it didn't somewhere. You mean earlier iOS versions? Yes, I haved used similar code in games around 2. I don't know about the iPhone in particular, but I may still be able to help: Instead of simply plugging in a fixed delay at the end of the loop, use the following: Determine a refresh interval that you would be happy with and that is larger than a single pass through your main loop.

At the start of the loop, take a current timestamp of whatever resolution you have available and store it. At the end of the loop, take another timestamp, and determine the elapsed time since the last timestamp initialize this before the loop. At the next frame, you can even try to compensate for inaccuracies in the sleep interval by comparing to the timestamp at the start of the previous loop. Galghamon Galghamon 1, 17 17 silver badges 27 27 bronze badges.

Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown.

The Overflow Blog. Podcast Making Agile work for data science. Stack Gives Back Featured on Meta.



0コメント

  • 1000 / 1000