2015-06-14 93 views
0

嘿,我正在尝试获取碰撞点,然后在两点处创建一个关节。我不确定我的结果是什么意思或如何得到我想要的。遇到问题碰撞点

我无法访问我在其他帖子中看到的联系点。来自碰撞的CCContactSet只给我点数和正常。

我在碰撞开始时输出法线,左壁为(1.0,-0.0),底壁为(-0.0,1.0),右壁为(-1.0,0.0),(-0.0,-1.0)顶墙。我基本上不了解他们。我知道他们只是指第二个船体,因为无论我在碰撞过程中如何旋转或定位助推器,结果都保持不变。如果我旋转船体件,它们只会改变。

那么我如何获得联系点来创建关节?我应该使用正常的,如果是这样的话?

newSprite = CCSprite(imageNamed: "Booster.png") 
newSprite.position = CGPoint(x: 200, y: 200) 
newSprite.scale = 4.0 
let spritePhysics = CCPhysicsBody(rect: newSprite.textureRect, cornerRadius: 0) 
spritePhysics.collisionType = "booster" 
spritePhysics.sensor = true 
newSprite.physicsBody = spritePhysics 
editorPhysics.addChild(newSprite) 

newSprite2 = CCSprite(imageNamed: "HullPiece.png") 
newSprite2.position = CGPoint(x: 200, y: 200) 
newSprite2.scale = 4.0 
let spritePhysics2 = CCPhysicsBody(rect: newSprite2.textureRect, cornerRadius: 0) 
spritePhysics2.collisionType = "hull" 
spritePhysics2.sensor = true 
newSprite2.physicsBody = spritePhysics2 
editorPhysics.addChild(newSprite2) 

func ccPhysicsCollisionBegin(pair: CCPhysicsCollisionPair!, booster: CCNode!, hull: CCNode!) -> ObjCBool 
{ 
    NSLog("contact point\(pair.contacts.count) \(pair.contacts.normal)") 
    return true 
} 

回答

0

你打通CCPhysicsCollisionPaircontacts财产获得的接触点。

这里的contacts结构是什么样子:

typedef struct CCContactSet { 
    /// The number of contact points in the set. 
    /// The count will always be 1 or 2. 
    int count; 

    /// The normal of the contact points. 
    CGPoint normal; 

    /// The array of contact points. 
    struct { 
     /// The absolute position of the contact on the surface of each shape. 
     CGPoint pointA, pointB; 

     /// Penetration distance of the two shapes. 
     /// The value will always be negative. 
     CGFloat distance; 
    } points[2]; 
} CCContactSet; 

通过points阵列,您可以访问准确的碰撞位置为每个参与的形状。

+1

感谢这是一个问题,迅速和cocos2d他们要补丁http://forum.cocos2d-spritebuilder.org/t/trouble-getting-collision-point/17582/3 – shwick

+0

感谢您的后续行动。没有注意到结构是匿名的:) –