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.
Using a ShapeNode instead of SpriteNode
-
So I am playing around with the Game Module and I have enjoyed swapping out coins for snowflakes and then slowed them down for a beautiful snowy day, but I want to do this with a ShapeNode and can't seem to figure it out..
class Coin (SpriteNode): def __init__(self, **kwargs): SpriteNode.__init__(self, 'emj:Snowflake', **kwargs)
If anyone can point me in the right direction to use a circle (ui.Path.oval) instead of a texture.
It tried thisclass Ball(ShapeNode): def __init__(self, **kwargs): circle = ui.Path.oval (0, 0, 20, 20) theball = ShapeNode(circle,'red', stroke_color='clear', shadow=None) ShapeNode.__init__(self, theball, *kwargs)
And it tells me the ShapeNode object has no attribute bounds.
Thanks in advance to anyone who can help. -
"init " method is not called properly. Here is some sample code that illustrates use of ShapeNode. Note that this works with python 3 and for working with python 2.7 you need to call super differently (super(Ball, self))
import scene, ui class Coin(scene.SpriteNode): def __init__(self, **kwargs): super().__init__('emj:Snowflake', **kwargs) class Ball(scene.ShapeNode): def __init__(self, **kwargs): circle = ui.Path.oval (0, 0, 20, 20) super().__init__(circle, fill_color='red', stroke_color='clear', shadow=None, **kwargs) class Polygon(scene.ShapeNode): def __init__(self, **kwargs): path = ui.Path() path.line_width = 5 path.move_to(0, 0) path.line_to(200, 0) path.line_to(100, 100) path.close() super().__init__(path, **kwargs) class MyScene(scene.Scene): def setup(self): self.ball = Ball(position=(200, 100), parent=self) self.coin = Coin(position=(200, 200), parent=self) self.triangle1 = Polygon(fill_color='skyblue', stroke_color='green', position=(200, 400), parent=self) self.triangle2 = Polygon(fill_color='red', stroke_color='green', position=(200, 300), parent=self) scene.run(MyScene())
-
@abcabc thanks a lot. One of the amazing thing about these forums is that people (like you) help out with great examples and no snark. I am really grateful. And hopefully when I have greased my wheeels a bit more I will also be to help others out.
So thanks again for pointing out my mistake.
The polygon you included also really helps understand the syntax better!