Quand on utilise get_rect() sur une image, la fonction donne une valeur par défaut (0,0).
Comment faire pour faire en sorte que mon image soit au centre de l'image par exemple?
Voici mon code honteusement pompé sur le tuto:
import pygame
from pygame.locals import *
pygame.init()
#Ouverture de la fenêtre Pygame
fenetre = pygame.display.set_mode((1000, 700))
#Chargement et collage du fond
fond = pygame.image.load("Fond_Nature.gif")
fenetre.blit(fond, (0,0))
#Chargement et collage du personnage
perso = pygame.image.load("Abe_marche1(G).gif")
position_perso = perso.get_rect()
fenetre.blit(perso, position_perso)
#Rafraîchissement de l'écran
pygame.display.flip()
pygame.key.set_repeat(400,30)
while 1:
for event in pygame.event.get(): #Attente des événements
if event.type == QUIT:
break
if event.type == KEYDOWN:
if event.key == K_DOWN: #Si "flèche bas"
#On descend le perso
position_perso = position_perso.move(-3,-3)
#Re-collage
fenetre.blit(fond, (0,0))
fenetre.blit(perso, position_perso)
#Rafraichissement
pygame.display.flip()
Merci.
P.s: Comment faire pour appeler une image qui se trouve dans un autre dossier ou répertoire?
The Rect object has several virtual attributes which can be used to move and align the Rect:
top, left, bottom, right
topleft, bottomleft, topright, bottomright
midtop, midleft, midbottom, midright
center, centerx, centery
size, width, height
w,h
All of these attributes can be assigned to:
rect1.right = 10
rect2.center = (20,30)
Assigning to size, width or height changes the dimensions of the rectangle; all other assignments move the rectangle without resizing it. Notice that some attributes are integers and others are pairs of integers.
× Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
× Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
Python c'est bon, mangez-en.