我有一个非常简单的程序。我想要的是物品类中的物品可以独立移动。
{
"queryType": "select",
"dataSource": "wikipedia",
"intervals": [
"2015-01-01/2016-01-02"
],
"pagingSpec":{"pagingIdentifiers": {}, "threshold":10}
}
在程序块中.move()执行一次但是全部,所以对象停留在同一个地方,只移动了一次。我试图将block.move()函数放在for和while循环中,但如果我这样做,程序就不会运行。任何人都可以告诉我如何修复我的代码,以便对象连续移动,所以它从一端移动到另一个屏幕?
答案 0 :(得分:0)
问题是你在while循环中重新初始化你的块,所以在每次迭代中你都将它重置到原来的位置然后移动它。尝试将初始化移到while循环之外:
def game_loop():
#game exit value is set
game_exit = False
block = things(100,100,4)
#when true you exit the loop, logic goes here
while not game_exit:
for event in pygame.event.get():
#method below on what to do if they press x in the corner
if event.type == pygame.QUIT:
#exit the loop
pygame.quit()
quit()
#fills the background
gameDisplay.fill(white)
block.drawImage(blockImg,block.X,block.Y)
block.move()
pygame.display.update()
clock.tick(30)