cocos2d/cocos2d-objc

CCContactSet not Swift compatible

pontusarmini opened this issue · 1 comments

The way that the CCContactSet struct is set up it seems as if it is not Swift compatible (as of Swift 2.0 and Xcode 7.0 beta). The countand normalvalues are visible in Swift but not the contact points array containing the contact points pointA, pointBand distancevalues. I have not been able to find any documentation explaining this phenomena, but with my own testing I've found that this issue is resolved by setting a tag/name of the inner points struct like so (I've named it ContactPoint):

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. As is this is an unnamed struct, but tagging/naming it makes it accessible in Swift
    struct ContactPoint {
        /// 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;

This will make the points array accessible in Swift with dot notation:

//Example from within a ccPhysicsCollisionBegin call
pair.contacts.points.0.pointA

(The CCContactSet is created by casting from the cpContactPointSet struct defined in cpArbter.h and this solution works without changing anything to that as far as I've tested this)

Fixed