固定距离关节不能正常工作

时间:2015-06-06 01:30:45

标签: ios swift cocos2d-iphone physics

我希望我的两艘船在恒定的距离点附着,所以我试图使用相应的关节。行为开始看似正确的运动,但几秒钟后,两个盒子只是漫无目的地漂移。

我在一个盒子上施加一个力来移动并确保它们不会碰撞。我搜索并发现一个人有类似的问题,但它看起来像是一个补丁被创建,所以我不知道它是否已修复。

import Foundation

class Battle: CCNode, CCPhysicsCollisionDelegate {

var scenePhysics = CCPhysicsNode()

override init() {
    super.init()

    scenePhysics.collisionDelegate = self
    self.addChild(scenePhysics)
    buildShip()
}

func buildShip(){

    var booster = CCSprite(imageNamed: "Booster.png")
    booster.position = CGPoint(x: 50, y: 150)
    booster.scale = 4
    var boosterPhysics = CCPhysicsBody(rect: booster.textureRect, cornerRadius: 0)
    boosterPhysics.collisionCategories = ["cat1"]
    boosterPhysics.collisionMask = ["cat2"]
    boosterPhysics.collisionType = "nodeA"
    boosterPhysics.applyForce(CGPoint(x: 2000, y: 1))
    booster.physicsBody = boosterPhysics
    scenePhysics.addChild(booster)


    var booster2 = CCSprite(imageNamed: "Booster.png")
    booster2.position = CGPoint(x: booster.position.x + 90, y: booster.position.y)
    booster2.scale = 4
    var boosterPhysics2 = CCPhysicsBody(rect: booster2.textureRect, cornerRadius: 0)
    boosterPhysics2.collisionCategories = ["cat2"]
    boosterPhysics2.collisionMask = []
    boosterPhysics2.collisionType = "nodeB"
    booster2.physicsBody = boosterPhysics2
    scenePhysics.addChild(booster2)


    CCPhysicsJoint(distanceJointWithBodyA: boosterPhysics, bodyB: boosterPhysics2, anchorA: CGPointZero, anchorB: CGPointZero)

}
}

1 个答案:

答案 0 :(得分:0)

K所以我把锚点改为boosterphysics的内容大小,并且用针接头工作,所以我现在很高兴。