Threading with update()?
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
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.
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.