0

I would like to create a game with multiple contact options but I need to find also condition when sprite is not with contact with any other body.

I don't want to be informed that sprite is losing contact like with didEnd function.

I need information that sprite has no contact at all...

How to do that?

Thank you

mamaz
  • 1
  • 5

1 Answers1

-1

you can use mySprite.physicsBody?.allContactedBodies() to get array of bodies that are in contact with your sprite. Then you can simply find out what bodies are not in contact with your sprite by excluding members of this array from all bodies.

  • Wow. It is working! Thanks I was thinking that I can oly call it in didBegin and didEnd contacts but I was wrong! Super!! Thank you very much! – mamaz Jul 11 '17 at 13:00
  • Hi It is not working... I tried to use that function in touchDown touchMove touchUp and it gives me empty array... allContactedBodies is working in didBegin and didEnd but I want to be informed when there is no contact at all. Do you have any idea how I can use that function without using didBegin and didEnd function? Thanks – mamaz Jul 12 '17 at 02:47
  • @mamaz it will return an empty array if it is not in contact with any body, check if your sprite it in contact with any. I've already use this function in update() – Galym Anuarbek Jul 12 '17 at 08:09
  • Galym Thank you very much! I almost ended my app worked hard for other solution and I fund your answer on my old problem. Update() Brilliant!! – mamaz Oct 13 '17 at 12:47
  • @mamaz not at all. It's a big surprise to get that message after 3 months :D – Galym Anuarbek Oct 14 '17 at 15:29