在PySDL2上裁剪精灵

时间:2018-08-06 00:11:49

标签: pysdl2

我刚开始在python上使用SDL2,但几乎立即陷入尝试裁剪图像/精灵的困境。任何想法?以下大部分内容摘自官方教程。显然,在这里,sprite.size不是我可以设置的属性,所以我可能需要另一种方法?

import sys
import sdl2.ext

RESOURCES = sdl2.ext.Resources(__file__, "resources")

def run():
    sdl2.ext.init()
    window = sdl2.ext.Window("Drawing Card Game", size=(640, 480))
    window.show()

    if "-hardware" in sys.argv:
        print("Using hardware acceleration")
        renderer = sdl2.ext.Renderer(window)
        factory = sdl2.ext.SpriteFactory(sdl2.ext.TEXTURE, renderer=renderer)
    else:
        print("Using software rendering")
        factory = sdl2.ext.SpriteFactory(sdl2.ext.SOFTWARE)

    spriterenderer = factory.create_sprite_render_system(window)
    sprite = factory.from_image(RESOURCES.get_path("mysprite.jpg"))
    sprite.size = (100,100) #AttributeError: can't set attribute
    spriterenderer.render(sprite)

    processor = sdl2.ext.TestEventProcessor()
    processor.run(window)
    sdl2.ext.quit()
    return 0

if __name__ == "__main__":
    sys.exit(run())

也欢迎在PySDL2上使用任何资源...

0 个答案:

没有答案