sprite kit - Swift SpriteKit SKPhysicsJointPin -


i'm trying implement rope in swift spritekit , add physics it, position all, won't attach, when hit play fall except first 1 "holder". here code:

    // create rope holder     let chainholder = skspritenode(imagenamed: "chainholder")      chainholder.position.y = self.frame.maxy - chainholder.size.height      chainholder.physicsbody = skphysicsbody(circleofradius: chainholder.size.width / 2)     chainholder.physicsbody?.dynamic = false     //chainholder.physicsbody?.allowsrotation = true      chains.append(chainholder)     addchild(chainholder)      // add each of rope parts     in 0...5 {          let chainring = skspritenode(imagenamed: "chainring")         let offset = chainring.size.height * cgfloat(i + 1)         chainring.position = cgpointmake(chainholder.position.x, chainholder.position.y - offset)         chainring.name = string(i)          chainring.physicsbody = skphysicsbody(rectangleofsize: chainring.size)         //chainring.physicsbody?.allowsrotation = true          chains.append(chainring)         addchild(chainring)     }      // set joints between rope parts     in 1...5 {          var nodea = chains[i - 1]         var nodeb = chains[i]         var joint = skphysicsjointpin.jointwithbodya(nodea.physicsbody, bodyb: nodeb.physicsbody,             anchor: cgpointmake(cgrectgetmidx(nodea.frame), cgrectgetminy(nodea.frame)))          physicsworld.addjoint(joint)     } 

i found out problem because setting anchor point scene in (0.5, 0.5). if leave in (0, 0) ok.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -