import pygame
#intialize the pygame
pygame.init()
# create the screen
screen = pygame.display.set_mode((800,600))
# Title and Icon
pygame.display.set_caption("Space Invader")
icon = pygame.image.load('spaceship (1).png')
pygame.display.set_icon(icon)
# Player
playerImg = pygame.image.load('ship.png.png')
playerX = 400
playerY = 490
def player(x,y):
screen.blit(playerImg, (x, y))
# game Loop
running = True
while running:
# RGB - Red, Green, Blue
screen.fill((0, 0, 0))
playerX += .1
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
player(playerX, playerY)
pygame.display.update()
答案 0 :(得分:0)
说
"DeprecationWarning: an integer is required (got type float). 不推荐使用 int 隐式转换为整数,可能会在 Python 的未来版本中删除。 screen.blit(playerImg, (x, y))"< /p>
警告与blit()
的坐标参数有关。浮点坐标意味着 Surface
的原点介于窗口中的像素之间。那没有多大意义。坐标会自动隐式截断,并由警告指示。
使用 int
或 round
将浮点坐标转换为整数:
def player(x,y):
screen.blit(playerStand, (round(x), round(y)))