SKPhysicsBody不适用于SKSpriteNode

时间:2017-09-22 01:26:46

标签: sprite-kit xcode9

我不会在界面构建器上使用“自定义类”作为示例“Walls”。

拖动SpriteNode并设置自定义类:Wall。

代码Wall.swift:

required init?(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)
    setup()
}

func setup() {
    self.color = .white // This works

    let body = SKPhysicsBody(rectangleOf: frame.size)

    body.isDynamic = true
    body.allowsRotation = false
    body.pinned = false
    body.affectedByGravity = true

    body.friction = 0.0
    body.restitution = 0.0
    body.linearDamping = 1.0
    body.angularDamping = 1.0

    body.mass = 1.0
    body.velocity = CGVector(dx: 0, dy: 0)
    body.density = 1.0
    body.charge = 1.0

    body.categoryBitMask = 4294967295
    body.collisionBitMask = 4294967295
    body.fieldBitMask = 4294967295
    body.contactTestBitMask = 0

    self.physicsBody = body
}

精灵将颜色变为白色,但physicsBody不起作用。

我做错了什么?

0 个答案:

没有答案