skphysicsbody collision between two same nodes

烈酒焚心 提交于 2019-12-24 23:07:08

问题


I created a class that declare a ball of kind 'SKShapeNode'. in its init I set the 'SKPhysicsBody' properties. before I set these properties (leave it as default) when one ball touch another one the both affected by the touch (like: move to different position depends on the collision position). after I set the 'physicsBody' properties it won't affected any more - one ball appear to be above the other one (like frame on frame - hiding it). how can I set this property? I look at apple doc and did find nothing... here is my code:

lass BallNode: SKShapeNode {
    var radius:CGFloat = 0
    var color:UIColor?
    var strokeWidth:CGFloat = 0
    private var _name:String?

override init() {
        super.init()
        self.fillColor = ranColor()
        self.lineWidth = strokeWidth

    }

convenience init(radius:CGFloat){
        self.init(circleOfRadius: radius)
        self.radius = radius
        self.physicsBody  = SKPhysicsBody.init(circleOfRadius: self.radius)
        self.physicsBody?.affectedByGravity = true
        print("ball physicsbody is init")
        self.physicsBody?.restitution = 0.2
        self.physicsBody?.linearDamping = 0.0
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }     
}

来源:https://stackoverflow.com/questions/47271850/skphysicsbody-collision-between-two-same-nodes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!