How to use scene.Rect? browsing

• posted
0

Hello. I have just started using scene and followed the tutorial at: http://omz-software.com/pythonista/docs/ios/scene.html#introduction.

I have created two SpriteNodes one is a spaceship and the other is a rock. And Im able to move the ship using the `touch_began` method.

So now I can move the ship over the screen but I would like something to happen to the ship if it touches the rock. I have looked at the game tutorial in pythonista and from the forth tutorial part there is something called "scene.Rect" used for that. I have tried using it in my scene and it only works if the ship is on the lower part of the screen. So my question is:
What should I use for my "ship" that moves all over the scene

Sorry for the long post.

• posted
0

@omz can you give me an example?
I understand what you mean but not how to do it

posted
1

@Bjucha Imagine a circle drawn around the center of the space ship and the rock. When the circles intersect, there is a collision. To check whether there is a collision, you simply have to calculate the distance between the center (position) of the space ship and the rock. If that distance is smaller than the radius of both circles combined, you have a collision.

Calculating the distance between two points is quite easy btw: `distance = abs(pos1 - pos2)`

• posted
0

@omz ok thanks! Gonna try it tonight

posted
0

@Bjucha Good luck! Btw, it can make sense to use circles that are a bit smaller than the actual object. This way, your collision detection won't feel "unfair" in some cases.

• posted
0

@omz really really greatful for your help, however Im lacking skill and knowledge to make this work for now...

But I looked at your game tutorial and found this

``````if item.position in self.ship.frame:
exit()
``````

That is working fine, not perfect but better then before
Thank you for your game tutorial it has taught me many things

• posted
0

``````distance = abs(item.position - self.ship.frame.center())
if distance < 20:
exit()
``````

• posted
0

@ccc thank you that worked really good for me. Love all the help from all of you

• posted
0

We just wanna play the game.

• posted
0

@ccc I promise that as soon as SpaceGalaxy (Name temporary, might be changed) is finished
You will have it

Internal error.

Oops! Looks like something went wrong!