omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    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

    Pythonista
    scene
    2
    3
    2502
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • OTPSkipper
      OTPSkipper last edited by ccc

      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:

      1. Why doesn't the color work on my plot class?
      2. Why isn't the plot 50 px from the lower left corner?
      3. Why are the x gifs not half size?
      4. Why doesn't the plot Sprite clip its children?
      1 Reply Last reply Reply Quote 0
      • omz
        omz last edited by omz

        1. Why doesn't the color work on my plot class?

        You're not setting color as an instance attribute, but the color class attribute you're creating "shadows" the normal property. You should set color and anchor_point in an __init__ method, as you've done (in part) with the pt 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'
        
        1. 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.

        1. Why are the x gifs not half size?

        First of all, the attributes you're looking for are called x_scale and y_scale, not scale_x and scale_y. Furthermore, if you set both to the same value anyway, you can just use scale.

        1. 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 the crop_rect property set for this purpose though, if you really need clipping behavior.

        1 Reply Last reply Reply Quote 0
        • OTPSkipper
          OTPSkipper last edited by

          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)
                  
                  ```
          1 Reply Last reply Reply Quote 0
          • First post
            Last post
          Powered by NodeBB Forums | Contributors