# How can I set decimal values to a Pygame rect position?

I'm trying to make the gravity a bit slower, like

Dog.rect.y += 0.5
print (Dog.rect.y)
screen.blit(background, (0, 0))
screen.blit(spikeUp0.image, (0, 0))
screen.blit(spikeDown0.image, (0, 436))
screen.blit(Dog.image, (Dog.rect.topleft))
pygame.display.update()


But the dog floats. The minimum I get set to y 1 with rect methods. How can I make it slower?

Here is the complete code in GitHub Gist

I'm not sure if it would work well, as I'm not familiar with pygame, but you could stick the value that you want in your Dog object as a float, and do calculations on this value, then use this value converted to int to update the rect.y variable.

Dog.computation_y += 0.5
Dog.rect.y = math.floor(Dog.computation_y)


You'll be able to control a bit more the rate at which the y will change. This also means that the object will not move every frame.

• Sorry but I can't understand. This is my first game I coded in Pygame. May 3, 2019 at 14:26
• What part could be clearer? May 3, 2019 at 14:28
• Is this part: "but you could stick the value that you want in your Dog object as a float, and do calculations on this value, then use this value converted to int to update the rect.y variable. Dog.computation_y += 0.5 Dog.rect.y = math.floor(Dog.computation_y)" May 3, 2019 at 15:23
• You can add a variable to you Dog object that is called computation_y. That variable is to be used to do the calculations: whenever you want to move the dog, you use that variable. This will allow to modify the position of the object the way you want. When you're ready to draw your Dog, use that value to set the position of the sprite (through the rect). This allows you to de-couple the logic from the rendering, which is something done pretty often. May 3, 2019 at 15:33

Ok, I did not remember that it was so easy only I had to increase the delay and done.
Sorry for inconvenience.

• It's good that you found a fix! Just be aware that you won't be able to use that fix when you'll have multiple objects moving at different speeds. May 3, 2019 at 18:52