how to make pygame use floats code example
Example: how to make pygame use float number
'''Pygame cannot adjust the image/rectangle position with floats,
because it rounds the float to an integer. But with this method it works'''
import pygame
pygame.__init__()
WIDTH = 300
HEIGHT = 300
screen = pygame.display.set_mode((WIDTH, HEIGHT))
class Sprite(pg.sprite.Sprite):
def __init__(self , pos_x , pos_y, img_name, size):
pg.sprite.Sprite.__init__(self)
self.pos_x = pos_x
self.pos_y = pos_y
self.image = pg.transform.scale(pg.image.load(img_name), size).convert()
self.rect = self.image.get_rect(center=(self.pos_x, self.pos_y))
def update(self):
pass
sprite_obj = Sprite(x, y,"IMAGE.png",(10,10))
all_sprites = pg.sprite.Group()
all_sprites.add(sprite_obj)
z = 0
def update_sprite():
all_sprites.remove(sprite_obj)
z += 1
sprite_obj = Sprite(z, y,"IMAGE.png",(10,10))
all_sprites.add(sprite_obj)
while True:
clock.tick(120)
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
all_sprites.draw(screen)
all_sprites.update()
update_sprite()
pygame.display.flip()