Python 需要让精灵保持旋转,而不是恢复到原始状态
因此,我正在尝试做一个赛车游戏,我有一个问题是a。我可以旋转播放器,但一旦我放开旋转键,它就会恢复到原来的位置B。我需要汽车根据汽车的旋转以一定角度行驶Python 需要让精灵保持旋转,而不是恢复到原始状态,python,pygame,Python,Pygame,因此,我正在尝试做一个赛车游戏,我有一个问题是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(
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()
无需两次加载图像这两个都是非常需要的,就像你移除一个图像并旋转它一样,播放器会在屏幕上出现故障注意到,是的,首先我会告诉你,要计算到哪里,你必须使用数学函数,这是一个教程(运动部分在那里,但你应该观看整个视频)它是俄语的,但这是我在寻找教程时唯一能找到的语言,但语言并不是那么重要,你只需要理解代码。无论如何,这些代码可以帮助您,所以请看一下整个教程。(链接指向一个特定的部分,该部分向您展示了旋转和填充所需的内容)