问题描述
为什么在render_rect()方法中创建的矩形“ test2”不渲染?我怀疑这与在调用render_rect()后不触发on_draw()或其他事情有关,但我不太清楚。如何在方法中正确使用pyglet中的形状,子图形等?
from pyglet import shapes
WHITE = (255,255,255)
HEIGHT = 1080
WIDTH = 720
window = pyglet.window.Window(HEIGHT,WIDTH)
background = pyglet.graphics.Batch()
test = shapes.Rectangle(200,200,50,color=WHITE,batch=background) # Renders successfuly
def render_rect():
test2 = shapes.Rectangle(300,300,batch=background) # Does not render
render_rect()
@window.event
def on_draw():
window.clear()
background.draw()
pyglet.app.run()
在我的other question中,这似乎是命名引用的问题,所以如果我这样做
def render_rect():
test2 = shapes.Rectangle(300,batch=background)
return test2
test = render_rect()
有效。但是,如果要在一种方法中定义多个形状怎么办?像这样:
def render_rects():
test2 = shapes.Rectangle(300,batch=background)
test3 = shapes.Rectangle(400,batch=background)
test4 = shapes.Rectangle(500,batch=background)
render_rects()
我是否真的必须返回列表中的所有形状并在方法之外逐一命名,还是有一种更简单的方法?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)