我有一个游戏的函数,message_box,它显示了一个很好的背景(雪碧图),在它的顶部有一个标签(它的文本是收到的string参数)。
当我调用它的方法draw()时,它工作了,并且精灵显示在屏幕上。但我需要在批处理中使用它,以便可以使用其他元素(在本例中为标签)呈现它。遗憾的是,只有标签会被渲染。我试着只将批处理与雪碧一起使用,但还是没有成功。
代码如下:
def message_box(self, string):
batch = pyglet.graphics.Batch()
dialog = pyglet.text.Label(string + " (Press ESC)",
font_name="Arial",
font_size=12,
x=cfg.resolution[0] / 3 + 26,
y=400,
anchor_x="center", anchor_y="center", batch=batch)
img = pyglet.resource.image('gui/dialog_full.png')
dia = pyglet.sprite.Sprite(img, batch=batch)
dia.x = 26
dia.y = 196
batch.draw()我是python和pyglet的初学者,所以我真的不知道这里发生了什么。
发布于 2013-05-20 14:25:58
您为您的标签提供了anchor_x和anchor_y的明确坐标,但没有提供您的图像。你确定你的雪碧图没有画在窗外吗?
发布于 2013-09-08 19:42:53
这可能是显卡的兼容性问题。
一个已知的问题是AMD/ATI卡:Pyglet: Sprite.draw() and Batch.draw() don't work, but Image.blit does
https://stackoverflow.com/questions/16309442
复制相似问题