0

Moving image in pygame

Hey guys! I know how tonset up a basic pygame window with a background. The next thing i would like to do is to move an other image in every 4 seconds automatically on this background. And also i would like to attach a text next to the moving image that is always next to it, and in every movement it prints an other text. Can you please help me how can i code it?

10th Jun 2021, 1:23 PM
1310balint
1310balint - avatar
6 Réponses
+ 1
Edit the x and y position in game loop!
10th Jun 2021, 1:26 PM
Abhiyantā
Abhiyantā - avatar
+ 1
Can you show your code!
10th Jun 2021, 1:38 PM
Abhiyantā
Abhiyantā - avatar
+ 1
https://www.pygame.org/docs/tut/MoveIt.html This is from Pygame's official site, hope it's help you 🙂
10th Jun 2021, 1:48 PM
Abhiyantā
Abhiyantā - avatar
0
And what about the 4 second refreshrate?
10th Jun 2021, 1:31 PM
1310balint
1310balint - avatar
0
#Pygame base import pygame #Color pre_definition BLACK = (0, 0, 0) WHITE = (255, 255, 255) RED = (255, 0, 0) GREEN = (0, 255, 0) BLUE = (0, 0, 255) pygame.init () #Screen size, name, refreshrate size = (800, 600) screen = pygame.display.set_mode(size) pygame.display.set_caption('TEST') done = False clock = pygame.time.Clock() background = pygame.image.load("").convert() #Main program loop while not done : for event in pygame.event.get() : if event.type == pygame.QUIT : done = True #Program logic screen.blit(background, [0,0]) #Drawing pygame.display.flip() clock.tick(60) #Close window pygame.quit()
10th Jun 2021, 1:41 PM
1310balint
1310balint - avatar
0
I will try it, thank you
10th Jun 2021, 2:24 PM
1310balint
1310balint - avatar