Ios 精灵套件多次碰撞

Ios 精灵套件多次碰撞,ios,swift,sprite-kit,sprite,collision,Ios,Swift,Sprite Kit,Sprite,Collision,我的游戏不是这样,而是这样: import SpriteKit class GameScene: SKScene, SKPhysicsContactDelegate { var sprite = SKSpriteNode() override func didMoveToView(view: SKView) { self.physicsBody = SKPhysicsBody(edgeLoopFromRect: self.frame)

我的游戏不是这样,而是这样:

import SpriteKit

class GameScene: SKScene, SKPhysicsContactDelegate {
    var sprite = SKSpriteNode()

    override func didMoveToView(view: SKView)
    {
        self.physicsBody = SKPhysicsBody(edgeLoopFromRect: self.frame)
        self.physicsBody?.categoryBitMask = 1
        self.physicsBody?.contactTestBitMask = 1
        self.physicsWorld.gravity = CGVectorMake(0, -10)
        self.physicsWorld.contactDelegate = self



    }
    func didBeginContact(contact: SKPhysicsContact) {
        print("contact")
    }

    override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?)
    {
        let spriteTexture = SKTexture(imageNamed: "Spaceship")
        sprite = SKSpriteNode(texture: spriteTexture)
        sprite.position = CGPoint(x: CGRectGetMidX(self.frame) , y: CGRectGetMidY(self.frame))
        sprite.size = CGSizeMake(80, 80)
        sprite.physicsBody = SKPhysicsBody(texture: spriteTexture, size: CGSizeMake(80, 80))
        sprite.physicsBody?.categoryBitMask = 1
        sprite.physicsBody?.collisionBitMask = 1
        sprite.physicsBody?.contactTestBitMask = 1
        sprite.physicsBody?.linearDamping = 0;

        self.addChild(sprite)

    }
}
如果粘贴此代码并运行,您将看到大量联系人字符串。我只需要1个联系人: 所以我想当接触只有一次碰撞


我编辑了我的问题,有人能帮忙吗?

1.基于SpriteKit从Xcode模板创建“基本游戏” 2.将下面的代码粘贴到游戏场景类


重要提示:尝试使用didEndContact委托方法而不是didBeginContact。在这种情况下,您将只得到一个调用,而didBeginContact会多次调用

然后你需要分开这些物体。。。你想要什么?接触是一种接触——你不能只说你只想要接触,这不是事情的运作方式。提供更多的信息,比如接触是如何发生的,你拥有什么样的物理体。也可以使用方形物理体,因为这种接触发生在使用polygonFromPathI制作的物理体上。我编辑,对不起,我的英语不好。谢谢你的所有答案,我可以修复,谢谢你的答案,在我的游戏中;2节点碰撞。我想,当collide只有一个联系人时,对不起,我的英语不好。你能把你的代码上传到github上并解释一下你需要什么吗?你能看到我的答案吗
class GameScene: SKScene, SKPhysicsContactDelegate {
    var sprite = SKSpriteNode()

    override func didMoveToView(view: SKView)
    {
        self.physicsBody = SKPhysicsBody(edgeLoopFromRect: self.frame)
        self.physicsBody?.categoryBitMask = 1
        self.physicsBody?.collisionBitMask = 1

        self.physicsWorld.gravity = CGVectorMake(0, -10)
        self.physicsWorld.contactDelegate = self

        self.physicsBody?.restitution = 0.0

    }

    func didEndContact(contact: SKPhysicsContact) {
        print("End contact")
    }

    override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?)
    {
        let spriteTexture = SKTexture(imageNamed: "Spaceship")
        sprite = SKSpriteNode(texture: spriteTexture)
        sprite.physicsBody = SKPhysicsBody(texture: spriteTexture, size: CGSizeMake(80, 80))

        sprite.size = CGSizeMake(80, 80)

        sprite.position = CGPoint(x: CGRectGetMidX(self.frame) , y: CGRectGetMidY(self.frame))
        sprite.physicsBody?.categoryBitMask = 1
        sprite.physicsBody?.collisionBitMask = 1
        sprite.physicsBody?.contactTestBitMask = 1
        sprite.physicsBody?.fieldBitMask = 1
        sprite.physicsBody?.restitution = 0

        self.addChild(sprite)

    }
}