I am studying cocos2d-x engine, I’m not very familiar with this topic, so I’m not sure if I did everything right.
I move the sprite to 5 pixels 60 times per second and, if the FPS falls, then I want the sprite to move to the same 5 * 60 pixels in a second, no less and no more. Did I correct the movement adjustment?
void HelloWorld::update(float delta) { float newPosX = sprite->getPositionX() + (xMovement * 5 * delta / 0.016666); float newPosY = sprite->getPositionY() + (yMovement * 5 * delta / 0.016666); sprite->setPosition(newPosX, newPosY); } I checked it by inserting this code into the update function, it seems to work:
if (RandomHelper::random_int(1, 100) == 5) Sleep(100); I know that I formulated the question badly, but I hope knowledgeable people will understand. If you have any idea how to do it differently, I’ll read it with pleasure.
The variables xMovement and yMovement have values of -1, 0, 1, depending on which keys are pressed.
deltain this code - is it the difference from the last frame? - VTT