이미지 (투명 이미지)를 보려고합니다. 제가 누르는 키를 회전 시키십시오. I.E. 플레이어의 머리를 위아래로 회전시키고 싶습니다 (머리에서 총을 쏘고 있습니다).하지만 코드 작성법에 대한 지침은 없습니다. 누구든지 나를 도울 수 있다면 크게 감사하겠습니다. 또한 나는 열쇠를 누르고있을 때 머리를 부드럽게 회전 (조준)하기를 원한다. 아래 코드 :파이 게임에서 키를 사용하여 이미지를 회전하는 방법은 무엇입니까?
import pygame
pygame.init()
white = (255,255,255)
BLACK = (0,0,0)
red = (255,0,0)
gameDisplay = pygame.display.set_mode((640,360))
background = pygame.image.load('background.jpg').convert()
player = pygame.image.load('BigShagHoofdz.png') #this must be rotateable
pygame.display.set_caption('Leslie is Lauw')
clock = pygame.time.Clock()
gameDisplay.blit(background, [0,0])
gameDisplay.blit(player, [-1,223])
pygame.display.update()
FPS = 60
direction = "Down"
def head():
if direction == "Down":
playerhead = player
if direction == "Up":
playerhead = pygame.transform.rotate(player, 60)
def gameLoop():
global direction
gameExit = False
while gameExit==False:
for event in pygame.event.get():
if event.type == pygame.QUIT:
gameExit = True
for event in pygame.event.get():
if event.type == pygame.QUIT:
gameExit = True
if event.key == pygame.KEYDOWN:
if event.key == pygame.K_UP:
direction = "Up"
elif event.key == pygame.K_DOWN:
direction = "Down"
clock.tick(60)
pygame.quit()
quit()
위로 또는 아래로 키를 눌렀을 때만 위아래로 회전해야하며 아래 또는 위로 밀면 부드럽게 움직여야합니다.
당신은 블릿'에 gameloop'에서()' – furas
내부'헤드()'당신은 지금 당신이 지역 만들기 때문에'글로벌 playerhead' 또는'반환 playerhead'을 사용해야합니다 while''()'내부가 변수. – furas
정상 이미지와 회전 이미지의 두 이미지를 전환하고 싶습니까? – skrx