ipad - Is there pixel perfect collision detection for Sprite Kit (iOS7)? -


i need spawn 8 random sprite objects on ipad sprite game. objects big, , different sizes. should not overlay. if 1 spawn on scene overlays removed (optional removes underlaying one). have been looking pixel perfect collision detection framework or helper class sprite kit. far haven't found tutorial or alike. people use normal collision detection not of since objects big. tested standard approach creates rectangles make sprite area in case bigger. sprite kit template testing project:

#import "wbmmyscene.h"  static const uint32_t randomobjectcategory     =  0x1 << 0;  @interface wbmmyscene () <skphysicscontactdelegate>  @end  @implementation wbmmyscene  -(id)initwithsize:(cgsize)size {     if (self = [super initwithsize:size])     {         /* setup scene here */         self.backgroundcolor = [skcolor colorwithred:0.15 green:0.15 blue:0.3 alpha:1.0];         self.physicsworld.gravity = cgvectormake(0, 0);         self.physicsworld.contactdelegate = self;     }     return self; }  -(void)touchesbegan:(nsset *)touches withevent:(uievent *)event {     /* called when touch begins */      (uitouch *touch in touches)     {         cgpoint location = [touch locationinnode:self];         skspritenode *spaceship = [skspritenode spritenodewithimagenamed:@"spaceship"];         //skspritenode *spaceship = [skspritenode spritenodewithcolor:[uicolor redcolor] size:cgsizemake(50, 50)];         spaceship.position = location;         [spaceship setsize:cgsizemake(50, 50)];         [spaceship.texture setfilteringmode:sktexturefilteringnearest];         //spaceship.texture setfilteringmode         spaceship.physicsbody = [skphysicsbody bodywithrectangleofsize:spaceship.size];         spaceship.physicsbody.dynamic = yes;         spaceship.physicsbody.categorybitmask = randomobjectcategory;         spaceship.physicsbody.contacttestbitmask = randomobjectcategory;         spaceship.physicsbody.collisionbitmask = 0;         [self addchild:spaceship];     } }  - (void)didbegincontact:(skphysicscontact *)contact {     // 1     skphysicsbody *firstbody, *secondbody;      if (contact.bodya.categorybitmask < contact.bodyb.categorybitmask)     {         firstbody = contact.bodya;         secondbody = contact.bodyb;     }     else     {         firstbody = contact.bodyb;         secondbody = contact.bodya;     }      // 2     if (firstbody.categorybitmask == secondbody.categorybitmask)     {         [self projectile:(skspritenode *) firstbody.node didcollitewitheachother:(skspritenode *) secondbody.node];     } }  - (void)projectile:(skspritenode *)object1 didcollitewitheachother:(skspritenode *)object2 {     nslog(@"hit");     [object1 removefromparent];     [object2 removefromparent]; }  -(void)update:(cftimeinterval)currenttime {     /* called before each frame rendered */ }  @end 

thanks time :)

as far i'm aware ios7 doesn't have per pixel physics, due come xcode 6 in beta testing phase , available developers now. remember beta , have few bugs, it's full release in september ios8 , new iphone.

in mean time have 2 options, download xcode 6 beta , work within per pixel physics. got little sick of using beta full development , instead went xcode 5. within ios7 , xcode 5 have option of defining physicsbody path, gives accurate depiction of sprites physical shape.

the tool use here , lets drag , drop image , define path points graphically , returns code, handy.

i hope helps!


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -