Hey guys, I'm having a difficult time in trying to code up where two sprites are touching but have an event if they no longer touch. I've googled quite a bit without much luck and tried what I know and got close but not quite. Just throwing a bone out here to see if anyone had any advice? Thanks!
It would be something like this: Code: BOOL currentCollisionState; BOOL previousCollisionState; -(void)spriteCollided { currentCollisionState = TRUE; } -(void)update { // state used to be 'collided' but now it's not if (!currentCollisionState && previousCollisionState) { NSLog(@"stopped colliding"); } previousCollisionState = currentCollisionState; }
Thanks for the reply BCarbone, I appreciate it. I ended up getting it working with this code: Code: float playerImageSize = [swimmer texture].contentSize.width; float boardImageSize = [board texture].contentSize.width; float boardCollisionRadius = boardImageSize * 0.37f;float playerCollisionRadius = playerImageSize * 0.37f; // This collision distance will roughly equal the image shapes. float maxCollisionDistance = playerCollisionRadius + boardCollisionRadius; // Get the distance between player and board. float actualDistance = ccpDistance(swimmer.position, board.position); // if (actualDistance < maxCollisionDistance) { Do This }