0

I don't use Physics Body as I want my sprites to overlap without colliding (when passing by for example). I have an array of textures for sprite attack animation and would like to know if it 'hit' other sprite with sword (and also woosh that goes behind).

Is there some easy way of knowing that?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
HelloimDarius
  • 695
  • 5
  • 23
  • 1
    If you want your sprites to overlap without colliding, why not just turn of collisions between the sprites you want to overlap? – Steve Ives Dec 06 '18 at 19:28
  • How would that help knowing if other sprite is 'touched' by the sword? – HelloimDarius Dec 06 '18 at 19:53
  • You're going to have to use physicsbodies however you can disable collisions between them. Check this out: https://stackoverflow.com/questions/21267600/is-it-possible-to-deactivate-collisions-in-physics-bodies-in-spritekit – KissTheCoder Dec 06 '18 at 21:29
  • @HelloimDarius Because you could then use physics bodies to check if the 2 sprites were contacting. – Steve Ives Dec 06 '18 at 23:10
  • Further to @Muffinman2497's response, check this answer: https://stackoverflow.com/a/22924783/2109038 , you can use this as a trigger, through which objects pass, but you're given a call when they contact. – Confused Dec 07 '18 at 08:31
  • I get that, but how would I know which part of the sprite collided? I don't really want to kill an enemy if he's only touched by the hand and not the sword, for example.. – HelloimDarius Dec 07 '18 at 12:51
  • @HelloimDarius Then make the sword a child node of the player sprite, and have different code for when the sword contacts an enemy to when the player contacts an enemy (presumably if the sword makes contact, the enemy dies and of the player makes contact, the player dies?) – Steve Ives Dec 10 '18 at 10:17
  • Just use the `intersect` method. No need to involve the physics engine if you are only doing contact testing – Knight0fDragon Dec 12 '18 at 14:43
  • `node.intersect` is essentially AABB testing. This is axis aligned based on the box of your sprite, so if the sprite is rotated, the box will be bigger. Depending on how accurate you want your collision to be, you may need to involve some more advanced methods. – Knight0fDragon Dec 12 '18 at 14:47
  • @Knight0fDragon well it sounds good to be honest. I'm just concerned if I check this for a big number of enemies inside Update method it will cause lag.. – HelloimDarius Dec 13 '18 at 15:00
  • Aabb is faster than physics – Knight0fDragon Dec 13 '18 at 15:44

0 Answers0