Basically, I’ve wanted to get back into Python, so I decided to make a small game in pygame, where there is a bouncy ball which you need to keep bouncing in the air. The problem is that when I use the functions clock.tick() and clock.get_time(), get_time should return the time passed in milliseconds, but it passes time in milliseconds*10.
My code:
GRAVITY = 10
def move(self, delta):
self.x+= (self.vx * delta)
self.y+= (self.vy * delta)
def speed(self, delta):
self.vy += (GRAVITY * delta)
clock.tick()
while True:
clock.tick()
delta = (clock.get_time() / 100) #should be /1000
ball.move(delta)
ball.speed(delta)
It works smoothly like in real world when its /100, but works really slow then its /1000.
I think part of the problem might be truncation from dividing by “1000” instead of “1000.0”. You can verify clock.tick is working with this:
Note that clock.tick already returns the delta and is normally used to cap the framerate. If left uncapped, you might have a really high FPS, giving a small delta and, when divided by an int, isn’t larger than 1 so you rarely get a number at all.
Also, make sure you have all your units right, that you really want to be converting to seconds