close
Maybe queuing the contacts and handle then in -update is what you need. For example:
Declare an instance variable called NSMutableArray *_contactQueue; Add the contacts to the array:
-(void) didBeginContact:(SKPhysicsContact*)contact
{[_contactQueue addObject:contact];}
Create a method to handle each contact in sync with your game ticks:
-(void)processContactsForUpdate:(NSTimeInterval)currentTime
{for(SKPhysicsContact* contact in [_contactQueue copy]){[self handleContact:contact];[_contactQueue removeObject:contact];}}
Call this method from update:
[self processContactsForUpdate:currentTime];
Then implement your handle method that will handle the contact.
-(void) handleContact:(SKPhysicsContact*)contact
{// What you are doing in your current didBeginContact method}
You can only handle the contact of two bodies, but in this way it's synchronized with every frame. I learned about this following a SpriteKit tutorial at this tutorial
http://stackoverflow.com/questions/21703835/two-or-more-collisions-at-same-time-in-sprite-kit
全站熱搜
留言列表