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.
Scene nube problems
-
Here is my test case:
from scene import Scene, SpriteNode, run, Point class pt(SpriteNode): def __init__(self, **kargs): SpriteNode.__init__(self, 'plf:HudX', **kargs) scale_x = 0.5 scale_y = 0.5 class plot (SpriteNode): anchor_point = Point(0,0) color = '#8989ff' class test(Scene): def setup(self): pane = plot(parent=self) pane.size = (self.size.x / 2, self.size.y / 2) pane.position = (50,50) for x in (50, 100, 150, 200, 250, 300): p = pt(parent=pane) p.position = (x, x) if __name__ == '__main__': tst = test() run(tst)
Questions:
- Why doesn't the color work on my plot class?
- Why isn't the plot 50 px from the lower left corner?
- Why are the x gifs not half size?
- Why doesn't the plot Sprite clip its children?
-
- Why doesn't the color work on my plot class?
You're not setting
color
as an instance attribute, but thecolor
class attribute you're creating "shadows" the normal property. You should setcolor
andanchor_point
in an__init__
method, as you've done (in part) with thept
class.It should look roughly like this:
class plot (SpriteNode): def __init__(self, **kargs): SpriteNode.__init__(self, **kargs) self.anchor_point = (0, 0) self.color = '#8989ff'
- Why isn't the plot 50 px from the lower left corner?
Basically the same answer as for the previous question, the
anchor_point
had no effect in your code.- Why are the x gifs not half size?
First of all, the attributes you're looking for are called
x_scale
andy_scale
, notscale_x
andscale_y
. Furthermore, if you set both to the same value anyway, you can just usescale
.- Why doesn't the plot Sprite clip its children?
Because that's just the way sprite nodes behave. Almost no kind of node clips its children. You could use an
EffectNode
with thecrop_rect
property set for this purpose though, if you really need clipping behavior. -
Got it. There is setter code in the library and I was overriding it. Here is the fixed code:
from scene import Scene, SpriteNode, run, EffectNode class pt(SpriteNode): def __init__(self, **kargs): SpriteNode.__init__(self, 'plf:HudX', **kargs) self.scale = 0.5 class plot (SpriteNode): def __init__(self, **kargs): SpriteNode.__init__(self, **kargs) self.anchor_point = (0, 0) self.color = '#8989ff' class test(Scene): def setup(self): clip = EffectNode(parent=self) clip.crop_rect = (0, 0, self.size.x / 2, self.size.y / 2) pane = plot(parent=clip) pane.size = (self.size.x / 2, self.size.y / 2) clip.position = (50, 50) for x in (50, 100, 150, 200, 250, 300, 350, 400): p = pt(parent=pane) p.position = (x, x) if __name__ == '__main__': tst = test() run(tst) ```