Ceci est une ancienne révision du document !
Le module transform de Pygame permet de créer de nouvelles surfaces Pygame en appliquant à une surface source une ou plusieurs transformations, isométriques ou non.
flip(Surface, xbool, ybool)
La fonction flip permet de faire une symétrie axiale, verticale ou horizontale ou les deux.
Elle prend en paramètre :
Si les deux booléens sont à True, alors on procède aux deux symétries.
IMG_FRAISE = pygame.image.load("fraise.png") IMG_FRAISE = pygame.transform.flip(IMG_FRAISE, True, True)
import pygame pygame.init() HAUTEUR = 400 LARGEUR = 400 COULEUR_FOND = (255, 255, 255) ECRAN = pygame.display.set_mode((LARGEUR, HAUTEUR)) ARRET = False # image FRAISE x_fraise = 50 y_fraise = 50 largeur_fraise = 40 hauteur_fraise = 40 IMG_FRAISE = pygame.image.load("fraise.png") # image Ballon x_ballon = 10 y_ballon = 10 largeur_ballon = 20 hauteur_ballon = 20 IMG_BALLON = pygame.image.load("ballon.png") ballonSpeed = [1, 0] #IMG_BALLON.move(ballonSpeed) ballonRect = IMG_BALLON.get_rect() while not ARRET: pygame.time.delay(100) ECRAN.fill(COULEUR_FOND) for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() elif event.type == pygame.KEYDOWN: if event.key == pygame.K_RIGHT: x_fraise = x_fraise + 4 elif event.key == pygame.K_LEFT: x_fraise = x_fraise - 4 ECRAN.blit(IMG_FRAISE, (x_fraise, y_fraise)) ECRAN.blit(IMG_BALLON, ballonRect) ballonRect = ballonRect.move(ballonSpeed) if ballonRect.right > LARGEUR: ballonSpeed[0] = - ballonSpeed[0] pygame.display.update()