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

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

在循環中使用并添加到 pygame 批處理

在循環中使用并添加到 pygame 批處理

HUWWW 2023-06-06 16:42:47
我正在使用 Pyglet 開發一個簡單的燭臺圖表繪圖程序。當我嘗試在一個循環中批處理形狀時,pyglet 只繪制第一個形狀(我認為)。我已經包含了一些最少的代碼來解釋我的問題。這段代碼應該在窗口上顯示 10 個又細又長的矩形,但我只得到一個矩形。import pygletfrom pyglet import shapeswindow = pyglet.window.Window(960, 540)batch = pyglet.graphics.Batch()for i in range(10):    rectangle = shapes.Rectangle(10*i, 100, 5, 100, color=(0,255,0), batch=batch)@window.eventdef on_draw():    window.clear()    batch.draw()pyglet.app.run()print(batch)這樣的事情很好用:rectangle1 = shapes.Rectangle(10, 100, 5, 100, color=(0,255,0), batch=batch)rectangle2 = shapes.Rectangle(20, 100, 5, 100, color=(0,255,0), batch=batch)rectangle3 = shapes.Rectangle(30, 100, 5, 100, color=(0,255,0), batch=batch)rectangle4 = shapes.Rectangle(40, 100, 5, 100, color=(0,255,0), batch=batch)rectangle5 = shapes.Rectangle(50, 100, 5, 100, color=(0,255,0), batch=batch)但這不會:rectangle = shapes.Rectangle(10, 100, 5, 100, color=(0,255,0), batch=batch)rectangle = shapes.Rectangle(20, 100, 5, 100, color=(0,255,0), batch=batch)rectangle = shapes.Rectangle(30, 100, 5, 100, color=(0,255,0), batch=batch)rectangle = shapes.Rectangle(40, 100, 5, 100, color=(0,255,0), batch=batch)rectangle = shapes.Rectangle(50, 100, 5, 100, color=(0,255,0), batch=batch)這對我來說意味著批處理對象只是指批處理中的形狀對象,這將使我無法使用 pyglet 批處理繪制圖形數據的計劃,我在這個假設中是否正確?
查看完整描述

1 回答

?
明月笑刀無情

TA貢獻1828條經驗 獲得超4個贊

我建議將形狀添加到列表中:

rectangles = [] 
for i in range(10): 
    rectangles.append(shapes.Rectangle(10*i, 100, 5, 100, color=(0,255,0), batch=batch))

分別

rectangles = [shapes.Rectangle(10*i, 100, 5, 100, color=(0,255,0), batch=batch) for i in range(10)]



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

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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