gpt4 book ai didi

swift - SpriteKit : Objects go underneath each other

转载 作者:搜寻专家 更新时间:2023-11-01 06:14:33 26 4
gpt4 key购买 nike

我的游戏中有两辆坦克,一辆红色一辆蓝色。

我已经设置了它们的 PhysicsBody,但它们没有相互撞击,而是在彼此下方。

Simulator Screenshot (1)

物理类别:

struct physicsCategory {
static let Bullet : UInt32 = 0x1 << 0
static let Enemy : UInt32 = 0x1 << 1
static let MainTank : UInt32 = 0x1 << 2
static let EnemyTank : UInt32 = 0x1 << 3
}

这是蓝色坦克代码:

MainTank = (self.childNode(withName: "tank") as? SKSpriteNode)!
MainTank.name = "blueTank"

MainTank.physicsBody?.categoryBitMask = physicsCategory.MainTank
MainTank.physicsBody?.collisionBitMask = physicsCategory.Enemy
MainTank.physicsBody?.contactTestBitMask = physicsCategory.Enemy

红色坦克的:

enemyTank = SKSpriteNode(imageNamed: "tank_red")
enemyTank.size = CGSize(width: 76, height: 92)
enemyTank.name = "enemyTank"
enemyTank.zPosition = 0
enemyTank.physicsBody = SKPhysicsBody(rectangleOf: enemyTank.size)
enemyTank.physicsBody?.categoryBitMask = physicsCategory.EnemyTank
enemyTank.physicsBody?.collisionBitMask = physicsCategory.Enemy
enemyTank.physicsBody?.contactTestBitMask = physicsCategory.MainTank

enemyTank.physicsBody?.isDynamic = false

最佳答案

换行就行了

enemyTank.physicsBody?.collisionBitMask = physicsCategory.Enemy

enemyTank.physicsBody?.collisionBitMask = physicsCategory.MainTank

关于swift - SpriteKit : Objects go underneath each other,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47872610/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com