当我最初加载节点时,我使用以下代码:
nodeHero.color = UIcolor .graycolor() nodeHero.size.wIDth = 20 nodeHero.size.height = 45 nodeHero.position.x = -frame.size.wIDth/2 + 45 nodeHero.position.y = pointMainY + 30 + nodeHero.size.height/2 nodeHero.zposition = 110 nodeHero.physicsBody = SKPhysicsBody(rectangleOfSize: CGSizeMake(nodeHero.size.wIDth,nodeHero.size.height)) nodeHero.physicsBody?.mass = 1 nodeHero.physicsBody?.angularVeLocity = 0 nodeHero.physicsBody?.allowsRotation = false nodeHero.physicsBody?.restitution = 0 nodeHero.physicsBody?.categoryBitMask = bitHero addChild(nodeHero)
当我向下滑动时,我希望能够做这样的事情(这不起作用):
nodeHero.size.height = 28 nodeHero.physicsBody?.size.height = 28
但我必须再次使用nodeHero.physicsBody = SKPhysicsBody(),它会重置所有其他physicsBody属性,所以我必须这样做:
nodeHero.size.height = 28 nodeHero.physicsBody = SKPhysicsBody(rectangleOfSize: CGSizeMake(nodeHero.size.wIDth,nodeHero.size.height)) nodeHero.physicsBody?.mass = 1 nodeHero.physicsBody?.angularVeLocity = 0 nodeHero.physicsBody?.allowsRotation = false nodeHero.physicsBody?.restitution = 0 nodeHero.physicsBody?.categoryBitMask = bitHero解决方法 According to SpriteKit documentation SKPhysicsBody的区域无法修改,因此您需要创建另一个SKPhysicsBody实例并复制要保留的值与上一个实例. 总结
以上是内存溢出为你收集整理的swift – 在运行时更改SpriteNode PhysicsBody大小全部内容,希望文章能够帮你解决swift – 在运行时更改SpriteNode PhysicsBody大小所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)