亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Python Turtle 點無緣無故閃爍

Python Turtle 點無緣無故閃爍

慕絲7291255 2023-01-04 16:52:52
在我的程序中,為了模擬運動,添加了點的x位置,清除舊點,繪制新點。def drawing_zombies():  clear()  for zombie in zombies:    goto(zombie.x, zombie.y)    dot(20, 'red')  update()def movement():  for zombie in zombies:    zombie.x -= 0.5  drawing_zombies()我見過一個極其相似的程序運行,它的點不閃,看起來是真的在動。但是,當我的程序運行時,它會閃爍(消失和重新出現的速度非??欤┢溆啻a在下面(除了一堆定義矢量類的東西,它與工作程序中的相同,所以它里面沒有任何問題)class vector(collections.abc.Sequence):    precision = 6    __slots__ = ('_x', '_y', '_hash')    def __init__(self, x, y):        self._hash = None        self._x = round(x, self.precision)        self._y = round(y, self.precision)    #The rest of the vector class would have been herezombies = []placement_options = [0, 1, 2, -1]def new_zombie():    placement_level = random.choice(placement_options)    z = vector(200, placement_level*100)    print(placement_level)    zombies.append(z)def drawing_zombies():  clear()  for zombie in zombies:    goto(zombie.x, zombie.y)    dot(20, 'red')  update()def movement():  for zombie in zombies:    zombie.x -= 0.5  drawing_zombies()  for z in zombies:    if z.x < -200:      done()  ontimer(movement(), 50)def gameplay():  setup(420, 420, 370, 0)  hideturtle()  up()  new_zombie()  movement()  done()gameplay()
查看完整描述

1 回答

?
德瑪西亞99

TA貢獻1770條經驗 獲得超3個贊

您可以使用該tracer(False)功能來禁用屏幕更新。所以基本上,所有的繪圖都是在內存中完成的,并且會在你調用時一次性復制到屏幕上tracer(True)。


def drawing_zombies():

  tracer(False)

  clear()

  for zombie in zombies:

    goto(zombie.x, zombie.y)

    dot(20, 'red')

  update()

  tracer(True)


查看完整回答
反對 回復 2023-01-04
  • 1 回答
  • 0 關注
  • 242 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號