首页 > 解决方案 > SKSpriteNodes 相互碰撞并粘在上面

问题描述

我的 SKSpritekit 节点相互堆叠并相互粘连。我已经通过 sks 文件并以编程方式添加了 SKSprite 节点。

let texture  = SKTexture(image: #imageLiteral(resourceName: "cone"))
trCone = SKSpriteNode(texture: texture, normalMap: texture)
//trCone?.texture = SKTexture(image: #imageLiteral(resourceName: "cone"))
trCone?.size = CGSize(width: 60, height: 65)
trCone?.position = CGPoint(x: 153, y: 267)
trCone?.zPosition = 15
trCone?.name = trainingStuff.text
trCone?.physicsBody = SKPhysicsBody(texture: SKTexture(image: #imageLiteral(resourceName: "cone")), size: CGSize(width: 60, height: 65))
trCone?.physicsBody?.allowsRotation = false
trCone?.physicsBody?.isDynamic = false
trCone?.physicsBody?.categoryBitMask = .zero
trCone?.physicsBody?.collisionBitMask = .zero
myTrainigArr?.append(trCone!)
self.myScene!.addChild(trCone!)

This is how I add the nodes. I would like them to overlap each other and pass through each other without any collisions but this is the outcome. When I try to move the nodes after they collide one is now stuck on top of the other. Any suggestions will be appreciated.

设置

当节点碰撞时

标签: swiftnodesskspritenode

解决方案


推荐阅读