如何解决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 举报,一经查实,本站将立刻删除。