Forum Archive

Transformation matrix?

Sebastian

I'm having som problems with the new node system of the 1.6 beta. Is there an equivalent to the previous scene.translate function?

JonB

Wouldn't you just use Node.position? Or Action.move_by?

Sebastian

I managed what I was trying to do, by using a "world node" and a "player node", the player node is just centered on the screen, while the world is the node that is actually being moved around. Now my collision detection fails, so I guess I have to use Node.point_to_scene or Node.point_from_scene, but I haven't figured out how they work.

JonB

See the new examples, such as BrickBreaker.py for ideas.
I think you want to use rect.intersects(bbox)

Sebastian

I'll try to explain it a bit further.
The objects that need collision detections are circles, so I checked if the cartesian distance between the two circles were less than the player circle's radius. I used a scene.ShapeNode as the world, that moves around the player, and that contains the other circles as child nodes. This makes the coordinates of the objects inside the world different from those in the scene.Scene. So I think I need some way to get the coordinates relative to the screen.

JonB

So, you could use point to scene on the circle center first. But, if all of your collision objects are direct subnodes of the world node:

 scene
 |
 +-- player
 |
 +-- world node
         |
         +-- ball1
         +-- ball2
         +-- etc

you could basically just add the world position to the ball,positions:

hit_test(player.bbox, world.ball1.bbox.translate(world.x,world.y))

Look at BrickBreaker's hit_test()... it does a quick interescts, followed by checking the distance. You could do something similar, except that for circle to circle collission you simply compute the distance between circle centers (you can just subtract the bbox.centers, which produces a Vector2, and you can use abs to get length of the vector efficiently) and check if it is greater than the sum of radii.

Sebastian

I think that's exactly what I'm looking for! Thanks @JonB :)