I’m developing a game using c++ and I don’t know what’s the better approach to my problem.
I have an array with gameObject objects, each one has an array with frames of animation that I loop through to show the animation in the game.
The animations are time based and I have to tell the objects how much time has passed since the last frame was displayed (deltaTime) to calculate what frame I will display in this iteration.
Everything ok until here.
Is it ok to feed the deltaTime to the objects with a setter method? Or would be better if I had a pointer in each object to a global variable? Or is there another even better approach here regarding performance and organization? Keep in mind that there’ll be hundreds of objects.
Thank you for your time 🙂
I’m developing a game using c++ and I don’t know what’s the better approach
Share
In general, avoid global variables. Just loop over the objects, passing the
deltaTimeto each:Storing the time within each object isn’t recommended, since anything you think you might need it for “in the future”, you should just do within
Update.