1

I have this function for a game, message_box, which shows a nice background(a Sprite) and in the top of it, a label(it's text is the string parameter received).

When I call the method draw() of it, it works, and the sprite is shown in the screen. But I need to use it in a batch, so it can be rendered with other elements(a Label in this case). Sadly, only the label get rendered. I've tried using the batch with only the Sprite but again, no luck.

Here is the code:

    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()

I'm a beginner in python and pyglet, so I really have no clue what's happening here.

Leprosy
  • 1,085
  • 4
  • 14
  • 36

2 Answers2

0

You gave your label definite coordinates for anchor_x and anchor_y, but not your image. Are you sure your sprite isn't drawing outside the window?

Crowbeak
  • 163
  • 7
0

It can be a compatibility issue with your graphics card.

A known issue is for AMD/ATI cards: Pyglet: Sprite.draw() and Batch.draw() don't work, but Image.blit does

Community
  • 1
  • 1
Rolf Schorpion
  • 523
  • 1
  • 4
  • 12