How to use scene.Rect?
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
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.
@omz can you give me an example?
I understand what you mean but not how to do it
@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)
@omz ok thanks! Gonna try it tonight
@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.
@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
distance = abs(item.position - self.ship.frame.center()) if distance < 20: exit()
@ccc thank you that worked really good for me. Love all the help from all of you
We just wanna play the game.
@ccc I promise that as soon as SpaceGalaxy (Name temporary, might be changed) is finished
You will have it