微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

需要让精灵保持旋转而不是恢复到原始状态

如何解决需要让精灵保持旋转而不是恢复到原始状态

所以我目前正在尝试做一个赛车游戏,我遇到的问题是 A。我可以旋转播放器,但是一旦我松开旋转键,它就会恢复到原来的位置 B。我需要汽车去根据汽车的旋转角度。

import pygame
#sets up the screen
pygame.init()
screen = pygame.display.set_mode((800,600))
pygame.display.set_caption("First Game")

player1 = pygame.image.load("player_1.png")
player1_x = 180
player1_y = 200
player1_rotation = 0
vel = 5

def player():
    screen.blit(player1,(player1_x,player1_y))

#where the main code is run
run = True
while run:
    pygame.time.delay(50)

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            run = False
    screen.fill((255,255,255))
    player()


    keys = pygame.key.get_pressed()


    player1 = pygame.image.load("player_1.png")
    if keys[pygame.K_LEFT]:
        player1_rotation += 5
        player1 = pygame.transform.rotate(player1,player1_rotation)
    if keys[pygame.K_RIGHT]:
        player1_rotation -= 5
        player1 = pygame.transform.rotate(player1,player1_rotation)
    if keys[pygame.K_UP]:
        player1_y -= vel

    
        
    pygame.display.update()

pygame.quit()

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。