自定义物理体添加不需要的额外线

时间:2015-11-21 12:13:38

标签: swift sprite-kit skphysicsbody

我已经制作了一个包含三个自定义物理实体的节点,但问题是每个物理主体都有一个额外的线。

我可以删除这些行吗?我要删除的行用红色圈出来。

我用this editor制作了物理机构。

通过我创建此代码的路径(swift& sprite kit):

//Wheel
    let wheel = SKSpriteNode(imageNamed: "wheel")
    let scaleWheel = frame.width / wheel.frame.width * 0.8
    wheel.name = "wheel"
    wheel.position = view.center

    //Scale constants
    let sprite = SKSpriteNode()
    sprite.position = CGPointMake(CGRectGetMidX(frame), CGRectGetMidY(frame))
    let offsetX: CGFloat = sprite.frame.size.width * sprite.anchorPoint.x
    let offsetY: CGFloat = sprite.frame.size.height * sprite.anchorPoint.y

    //path
    let path: CGMutablePathRef = CGPathCreateMutable()

    CGPathMoveToPoint(path, nil, -172 - offsetX, 143 - offsetY)
    CGPathAddLineToPoint(path, nil, -151 - offsetX, 122 - offsetY)
    CGPathAddLineToPoint(path, nil, -167 - offsetX, 100 - offsetY)
    CGPathAddLineToPoint(path, nil, -178 - offsetX, 81 - offsetY)
    CGPathAddLineToPoint(path, nil, -186 - offsetX, 60 - offsetY)
    CGPathAddLineToPoint(path, nil, -191 - offsetX, 38 - offsetY)
    CGPathAddLineToPoint(path, nil, -193 - offsetX, 16 - offsetY)
    CGPathAddLineToPoint(path, nil, -193 - offsetX, -7 - offsetY)
    CGPathAddLineToPoint(path, nil, -193 - offsetX, -25 - offsetY)
    CGPathAddLineToPoint(path, nil, -188 - offsetX, -47 - offsetY)
    CGPathAddLineToPoint(path, nil, -182 - offsetX, -69 - offsetY)
    CGPathAddLineToPoint(path, nil, -173 - offsetX, -88 - offsetY)
    CGPathAddLineToPoint(path, nil, -164 - offsetX, -105 - offsetY)
    CGPathAddLineToPoint(path, nil, -151 - offsetX, -124 - offsetY)
    CGPathAddLineToPoint(path, nil, -134 - offsetX, -143 - offsetY)
    CGPathAddLineToPoint(path, nil, -150 - offsetX, -168 - offsetY)
    CGPathAddLineToPoint(path, nil, -170 - offsetX, -147 - offsetY)
    CGPathAddLineToPoint(path, nil, -190 - offsetX, -121 - offsetY)
    CGPathAddLineToPoint(path, nil, -207 - offsetX, -89 - offsetY)
    CGPathAddLineToPoint(path, nil, -218 - offsetX, -58 - offsetY)
    CGPathAddLineToPoint(path, nil, -224 - offsetX, -23 - offsetY)
    CGPathAddLineToPoint(path, nil, -224 - offsetX, 25 - offsetY)
    CGPathAddLineToPoint(path, nil, -216 - offsetX, 62 - offsetY)
    CGPathAddLineToPoint(path, nil, -208 - offsetX, 85 - offsetY)
    CGPathAddLineToPoint(path, nil, -192 - offsetX, 116 - offsetY)

    CGPathCloseSubpath(path)

    //pathTwo
    let pathTwo: CGMutablePathRef = CGPathCreateMutable()

    CGPathMoveToPoint(pathTwo, nil, -93 - offsetX, 170 - offsetY)
    CGPathAddLineToPoint(pathTwo, nil, -117 - offsetX, 193 - offsetY)
    CGPathAddLineToPoint(pathTwo, nil, -93 - offsetX, 205 - offsetY)
    CGPathAddLineToPoint(pathTwo, nil, -66 - offsetX, 215 - offsetY)
    CGPathAddLineToPoint(pathTwo, nil, -43 - offsetX, 221 - offsetY)
    CGPathAddLineToPoint(pathTwo, nil, -21 - offsetX, 224 - offsetY)
    CGPathAddLineToPoint(pathTwo, nil, -2 - offsetX, 226 - offsetY)
    CGPathAddLineToPoint(pathTwo, nil, 22 - offsetX, 226 - offsetY)
    CGPathAddLineToPoint(pathTwo, nil, 46 - offsetX, 221 - offsetY)
    CGPathAddLineToPoint(pathTwo, nil, 63 - offsetX, 216 - offsetY)
    CGPathAddLineToPoint(pathTwo, nil, 85 - offsetX, 209 - offsetY)
    CGPathAddLineToPoint(pathTwo, nil, 111 - offsetX, 197 - offsetY)
    CGPathAddLineToPoint(pathTwo, nil, 137 - offsetX, 179 - offsetY)
    CGPathAddLineToPoint(pathTwo, nil, 160 - offsetX, 160 - offsetY)
    CGPathAddLineToPoint(pathTwo, nil, 181 - offsetX, 135 - offsetY)
    CGPathAddLineToPoint(pathTwo, nil, 200 - offsetX, 106 - offsetY)
    CGPathAddLineToPoint(pathTwo, nil, 214 - offsetX, 74 - offsetY)
    CGPathAddLineToPoint(pathTwo, nil, 223 - offsetX, 37 - offsetY)
    CGPathAddLineToPoint(pathTwo, nil, 192 - offsetX, 37 - offsetY)
    CGPathAddLineToPoint(pathTwo, nil, 186 - offsetX, 65 - offsetY)
    CGPathAddLineToPoint(pathTwo, nil, 170 - offsetX, 99 - offsetY)
    CGPathAddLineToPoint(pathTwo, nil, 139 - offsetX, 137 - offsetY)
    CGPathAddLineToPoint(pathTwo, nil, 95 - offsetX, 169 - offsetY)
    CGPathAddLineToPoint(pathTwo, nil, 46 - offsetX, 191 - offsetY)
    CGPathAddLineToPoint(pathTwo, nil, -4 - offsetX, 195 - offsetY)
    CGPathAddLineToPoint(pathTwo, nil, -61 - offsetX, 183 - offsetY)

    CGPathCloseSubpath(pathTwo)

    //pathThree
    let pathThree: CGMutablePathRef = CGPathCreateMutable()

    CGPathMoveToPoint(pathThree, nil, 192,-38 - offsetY)
    CGPathAddLineToPoint(pathThree, nil, 223,-38 - offsetY)
    CGPathAddLineToPoint(pathThree, nil, 219,-61 - offsetY)
    CGPathAddLineToPoint(pathThree, nil, 209,-91 - offsetY)
    CGPathAddLineToPoint(pathThree, nil, 196,-116 - offsetY)
    CGPathAddLineToPoint(pathThree, nil, 176,-145 - offsetY)
    CGPathAddLineToPoint(pathThree, nil, 149,-172 - offsetY)
    CGPathAddLineToPoint(pathThree, nil, 111,-198 - offsetY)
    CGPathAddLineToPoint(pathThree, nil, 79,-213 - offsetY)
    CGPathAddLineToPoint(pathThree, nil, 46,-222 - offsetY)
    CGPathAddLineToPoint(pathThree, nil, 15,-227 - offsetY)
    CGPathAddLineToPoint(pathThree, nil, -19,-226 - offsetY)
    CGPathAddLineToPoint(pathThree, nil, -49,-222 - offsetY)
    CGPathAddLineToPoint(pathThree, nil, -71,-216 - offsetY)
    CGPathAddLineToPoint(pathThree, nil, -87,-209 - offsetY)
    CGPathAddLineToPoint(pathThree, nil, -72,-183 - offsetY)
    CGPathAddLineToPoint(pathThree, nil, -39,-194 - offsetY)
    CGPathAddLineToPoint(pathThree, nil, 5,-197 - offsetY)
    CGPathAddLineToPoint(pathThree, nil, 52,-189 - offsetY)
    CGPathAddLineToPoint(pathThree, nil, 99,-170 - offsetY)
    CGPathAddLineToPoint(pathThree, nil, 141,-136 - offsetY)
    CGPathAddLineToPoint(pathThree, nil, 176,-87 - offsetY)

    CGPathCloseSubpath(pathThree)

    //Physics bodies
    let bodyOne = SKPhysicsBody(polygonFromPath: path)
    let bodyTwo = SKPhysicsBody(polygonFromPath: pathTwo)
    let bodyThree = SKPhysicsBody(polygonFromPath: pathThree)

    wheel.physicsBody = SKPhysicsBody(bodies: [bodyOne, bodyTwo, bodyThree])
    wheel.physicsBody!.angularDamping = 5
    wheel.physicsBody?.pinned = true
    wheel.physicsBody?.affectedByGravity = false
    wheel.physicsBody?.restitution = 1
    wheel.setScale(scaleWheel)
    addChild(wheel)

Picture of the problem

1 个答案:

答案 0 :(得分:0)

发现它!我做了一些额外的研究,this帖子出现了。

解决方案:

  

使用<form class="shoppingform" action="someaction.php" method="get" enctype="multipart/form-data"> Step1: Your details <br> <div class="customername"> <label class="formlabel">Name:</label> <input type="text"> </div> </form>bodyWithEdgeLoopFromPath:可以创建凹面碰撞形状。这些机构不会   动态的,不能自己移动,但他们是   任意碰撞形状与静态的完美解决方案   球场。