Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
How do I convert a ui.Image into a scene.SpriteNode?
-
import scene def make_oval_sprite(width=100, height=100, fg_color='blue', bg_color='grey'): with scene.ui.ImageContext(width, height) as ctx: scene.ui.set_color(bg_color) scene.ui.Path.rounded_rect(0, 0, width, height, height / 10).fill() scene.ui.set_color(fg_color) scene.ui.Path.oval(0, 0, width, height).fill() return ctx.get_image() class MyScene(scene.Scene): def setup(self): # scene.SpriteNode() wants an image name, not an image. scene.SpriteNode(make_oval_sprite(), parent=self, position=(200,200)) scene.run(MyScene()) # make_oval_sprite().show()
-
You have to cast the
ui.Image
into ascene.Texture
. Something like that:return scene.Texture(ctx.get_image())