Search code examples
iosxcodeswiftcollision-detection

Is there a function for no collisionTest in swift?


I know this may sound weird, but I'm wondering if there is a way I can set a method for is my sprite doesn't make contact with anything. For example; if my sprite doesn't touch an object the game is over. I'm very sorry I can't provide any sample codes because I have absolutely no idea how to do what I just described. Usually for my CollisionTests I would simply import this:

didBeginContact(contact: SKPhysicsContact) {
    let firstnode = contact.bodyA.categoryBitMask | contact.bodyB.categoryBitMask
    switch(firstnode){
    case Body.faceMask.rawValue | Body.redPoint.rawValue:
        //gameOver = true
        sampleMethod()
    default:
        print("a")
    }

I don't think it's possible to set an else method inside there because I tried and it gave me errors.


Solution

  • This should really be a comment but I don't have enough rep yet!

    What is your sprite trying to do? For example is it like a projectile that gets fired from somewhere? And if it misses you loose?

    When you give your sprite an action, can you give it an action to complete after that?

    For example:

    let actionMove = SKAction.moveTo(CGPoint(10, 10), duration: 1.0)
    let actionMoveDone = SKAction.rubBlock() {
        // Code here to run after the object finishes moving
    }
    sprite.runAction(SKAction.sequence([actionMove, actionMoveDone]))