Is it possible to deactivate collisions in physics bodies in spriteKit?

前端 未结 4 1924
栀梦
栀梦 2020-12-09 19:12

I\'m looking at doing the best way to collect items with my hero in my spriteKit game for iOs, and after to try a few ways to do it, my conclusion is the best way would be t

4条回答
  •  粉色の甜心
    2020-12-09 19:43

    contactTestBitMask is used to trigger didBeginContact. collisionBitMask is used to activate physics on nodes.

    // add a physics body
    ship.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:ship.size.width/2];
    
    // set the category for ship
    ship.physicsBody.categoryBitMask = shipCategory;
    
    // detect collisions with asteroids and edges
    ship.physicsBody.contactTestBitMask = asteroidCategory | edgeCategory;
    
    // physically collide with asteroids
    ship.physicsBody.collisionBitMask = asteroidCategory;
    

提交回复
热议问题