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.


    How to add border size, border colors in SpriteNodes?

    Pythonista
    3
    4
    813
    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.
    • ilikepython
      ilikepython last edited by

      Hello, this is my first post, and I am new to the scene library, I don’t know how to add border colors nor know how to change the border size and if it’s possible, can someone please tell me how?

      cvp 1 Reply Last reply Reply Quote 0
      • JonB
        JonB last edited by

        I don't think sprite node had a good built in method for this. You could, in setup, draw your sprite into a ImageContext, and then a stroke a rect on top. Then pass the ctx.get_image() as the image to your sprite node.

        cvp 1 Reply Last reply Reply Quote 1
        • cvp
          cvp @JonB last edited by cvp

          @JonB I would prefer fill the ImageContext with a color, then draw the image in it... 😂

          import ui
          from scene import *
          
          class MyScene (Scene):
          	def setup(self):
          		self.background_color = 'midnightblue'
          
          		ui_image = ui.Image.named('test:Mandrill')
          		wi,hi = ui_image.size
          		w = 100
          		h = w * hi/wi
          		bs = 10
          		with ui.ImageContext(w,h) as ctx:
          			pth= ui.Path.rect(0,0,w,h)
          			ui.set_color('red')
          			pth.fill()
          			ui_image.draw(bs,bs,w-2*bs,h-2*bs)
          			ui_image = ctx.get_image()
          		texture = Texture(ui_image)				
          		self.ship = SpriteNode(texture)
          		
          		
          		self.ship.position = self.size / 2
          		self.add_child(self.ship)
          
          run(MyScene())
          

          1 Reply Last reply Reply Quote 1
          • cvp
            cvp @ilikepython last edited by cvp

            @ilikepython previous post also for you

            1 Reply Last reply Reply Quote 0
            • First post
              Last post
            Powered by NodeBB Forums | Contributors