Python-Pyglet-无法同时绘制动画和精灵

问题描述

我正在尝试将gif指针指向指向被选中时作为播放按钮的图像,而在启动游戏时将其选中。我正计划在另一侧添加一个区域,但是要等到此问题解决后才能这样做。 这是代码

import pyglet

window = pyglet.window.Window(1280,720)
window.set_vsync(False)
window.set_caption("Crea's game")
pyglet.resource.path = ["game/resources"]
pyglet.resource.reindex()


def calc_center_x(imageX):
   window_width = window.width
   new_x = window_width // 2 - imageX // 2
   return new_x


selected = "Play"

animations = pyglet.graphics.Batch()
batch = pyglet.graphics.Batch()


def main_menu():
   background = pyglet.graphics.OrderedGroup(0)
   foreground = pyglet.graphics.OrderedGroup(1)
   menu_name = pyglet.resource.image("menu/MenuName.png")
   menu_name_obj = pyglet.sprite.Sprite(img=menu_name,x=calc_center_x(menu_name.width),y=(window.height-menu_name.height),group=foreground,batch=batch)
   play_button = pyglet.resource.image("menu/play.png")
   play_button_obj = pyglet.sprite.Sprite(img=play_button,x=calc_center_x(play_button.width),y=(menu_name_obj.y - play_button.height - 50),batch=batch)
   settings_button = pyglet.resource.image("menu/settings.png")
   settings_button_obj = pyglet.sprite.Sprite(img=settings_button,x=calc_center_x(settings_button.width),y=(play_button_obj.y - settings_button.height - 50),batch=batch)
   quit_button = pyglet.resource.image("menu/quit.png")
   quit_button_obj = pyglet.sprite.Sprite(img=quit_button,x=calc_center_x(quit_button.width),y=(settings_button_obj.y - quit_button.height - 50),batch=batch)
   if selected == "Play":
       pointer1 = pyglet.resource.animation("menu/pointer.gif")
       pointer1_obj = pyglet.sprite.Sprite(img=pointer1,x=(play_button_obj.x - 48),y=play_button_obj.y,batch=animations)


@window.event
def on_draw():
   window.clear()
   batch.draw()
   animations.draw()


if __name__ == "__main__":
   main_menu()
   pyglet.app.run()

让我知道你们是否都想要我正在使用的图像,它们的质量较低,但是它们应该可以工作

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)