简体   繁体   中英

Improve performance of game's update loop?

I have a piece of code for a small game and at some point my code basically "updates" all my objects. For my player this involves checking if any movement key is pressed, then it should stop the "update" function for the player and move onto the next object. I have found that it goes extremely slow over the player "update" function.

Basically if I move my player my "update all" goes much faster than when it doesn't move at all. Is there a fast way to let my void "update" for my player go faster when no "if" criteria are met (as in, no movement keys pressed)?

EDIT: im using c++

You definitely need to run a profiler, there're a lot available, choose one to your liking. It will show you how much time your program spends in every function. Once you know which precise lines of code are to blame, it's usually easy to fix it.

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