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.


    Threading with update()?

    Pythonista
    threading scene
    3
    3
    2573
    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.
    • Koopa
      Koopa last edited by Koopa

      Im not too familiar with threading but I thought I shoud use it for a physics test program I made with scene

      Is it a good idead to start a new thread like this every time or should I do this a different way?

      (This basically checks to see if the circles collide with each other and changes color if it happens; and this is only a portion of the program)

      def update(self):
      		for circle in self.circles:
      			_thread.start_new_thread(self.check_collision, (circle, ))
      				
      	def check_collision(self, circle):
      		for other in self.circles:
      			if circle != other:
      				dx = circle.position.x - other.position.x
      				dy = circle.position.y - other.position.y
      				if math.hypot(dx, dy) < (circle.radius + other.radius):
      					circle.color = COLLIDE_COLOR
      					break
      				else:
      					circle.color = CIRCLE_COLOR
      
      1 Reply Last reply Reply Quote 0
      • JonB
        JonB last edited by

        Generally you don't want to use threading in scene. Scene is very deterministic -- update gets called at a fixed rate, and the only things that happen happen at that rate. So if you want to check if a collision occurs in this frame, you check in this frame.

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

          http://omz-software.com/pythonista/docs/ios/scene.html#scene.run or http://omz-software.com/pythonista/docs/ios/scene.html#scene.SceneView.frame_interval might allow you that have more time per frame by having fewer frames per second.

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