我希望能够在用户向下滑动时更改节点的physicsBody高度,但除了重置整个physicsBody之外,还无法找到如何执行此操作.
当我最初加载节点时,我使用以下代码:
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
解决方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。