Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/356.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python PyGame中的图像运动_Python_Pygame - Fatal编程技术网

Python PyGame中的图像运动

Python PyGame中的图像运动,python,pygame,Python,Pygame,所以我正在用PyGame制作一个21点游戏,作为学校项目的一部分。我想添加卡片“走出甲板”的动画。我环顾四周,没有找到任何适合我的 我的问题是每次移动卡片时都会显示卡片图像,而不是一个图像移动到新的坐标集。当我只想让一个图像自行移动时,它会显示相同图像的10个。让图像从起点移动到终点,而不是在每一组新坐标上都显示图像的最佳方法是什么 如果您感兴趣,我将使用以下代码: def userCalculationsDisplay(gamestate): for i in range(0,len(

所以我正在用PyGame制作一个21点游戏,作为学校项目的一部分。我想添加卡片“走出甲板”的动画。我环顾四周,没有找到任何适合我的

我的问题是每次移动卡片时都会显示卡片图像,而不是一个图像移动到新的坐标集。当我只想让一个图像自行移动时,它会显示相同图像的10个。让图像从起点移动到终点,而不是在每一组新坐标上都显示图像的最佳方法是什么

如果您感兴趣,我将使用以下代码:

def userCalculationsDisplay(gamestate):
    for i in range(0,len(gamestate.UsersCardsList)):
        image = pygame.image.load(gamestate.PlayingCards[gamestate.UsersCardsList[i]])
        image = pygame.transform.scale(x2, (100, 150))
        printTest(gamestate)
        gamestate.MovingImageXCoordinate = (550)
        gamestate.MovingImageYCoordinate = (300)
        gamestate.x_change = 0
        gamestate.y_change = 0
        listOfCoordinatesToMoveCard = []
        for j in range(0, 10):
                gamestate.x_change = -10
                gamestate.y_change = 10
                gamestate.MovingImageXCoordinate += gamestate.x_change
                gamestate.MovingImageYCoordinate += gamestate.y_change
                windowSize.blit(image, (gamestate.MovingImageXCoordinate, gamestate.MovingImageYCoordinate))
                pygame.display.flip()
    printTest(gamestate)
    gamestate.userTotal = calculations(gamestate)
    if gamestate.userTotal > 21:
        drawFunction(48, "BUST!", colours.Black, 130, 360)
        gamestate.isPlayerFinished=True
        gamestate.isPlayerBust=True
        gamestate.standButtonAvailable=False
        gamestate.isGameFinished=True
    else:
        pass

    drawFunction(28, "Your card total is " + str(gamestate.userTotal), colours.Black, 130, 480)

这是一个老问题,但你能附上一张你的意思的截图吗?@Octo希望这有助于你在移动图像之前覆盖图像。每次你在屏幕上blit一些东西,它会一直停留在那里,直到被另一个图像覆盖,这就是为什么你会看到10个图像。你要做的是在下一张图片之前,在图片上加上背景(从而“删除”它)。正如@TedKleinBergman所说的,你必须清除屏幕,重新绘制所有内容。或者你可以只重绘你移动卡片的这一部分。