简体   繁体   中英

using NSTimer to move objects on screen

I am building a simple ios gaming app where I have to move a few objects on screen, and these moving objects react to swipe gestures and change their direction based on that. I am not using spritekit or any other gaming framework for this, and the way I am moving the objects is by triggering an NSTimer that fires 60 times a second. I am not using any threads explicitly so I guess the timer is executed by the main thread ? The code block that the timer triggers updates the location of objects based on their speed (defined as pixels per time unit in x/y direction). It is working fine and I am almost at the end of my project, but while testing the app I've realized that although the movement of objects seem pretty good most of the times, however sometimes the movement is a little rough/patchy. My question is that is it the right way to do something like this, how can I improve the performance ? will using something like GCD can help with the issue of jittery movement ? (I haven't looked into GCD in detail but I am willing to spend time on it if I know that will help)

Thanks for any help !

and the way I am moving the objects is by triggering an NSTimer that fires 60 times a second

I would recommend not doing that. Various forms of animation are built in (View animation, Layer animation, CADisplayLink, UIKit Dynamics), and of course there's always Sprite Kit. Use the tools you are given for this purpose. Don't reinvent the unicycle when you already have a Ducati at your disposal.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM