Skip to content

CCPhysicsJoint: expose subclasses and their properties AND/OR allow joints to be "revalidated" #951

Open
@LearnCocos2D

Description

@LearnCocos2D

Currently CCPhysicsDistanceJoint and other CCPhysicsJoint subclasses are in a private header. Furthermore, even the subclasses don't expose all of the joint's properties hidden within the ChipmunkConstraint class.

The use case is that one has to remove a joint, and later create the (exact) same joint again because invalidated joints can't simply be re-activated once invalidated. But with SpriteBuilder one has no access to the joint's init parameters (ie stiffness, damping, min/max distance etc) because the joint is created somewhere within CCBReader.

So even if you keep a reference to the joint in question, you can only gain access to its bodies but not the joint's properties. Example code snippet:

    _lockJoint = [CCPhysicsJoint connectedDistanceJointWithBodyA:_lockJoint.bodyA
                                                           bodyB:_lockJoint.bodyB
                                                         anchorA:CGPointMake(0.0, -300.0)
                                                         anchorB:CGPointMake(32.0, 32.0)
                                                     minDistance:223.0
                                                     maxDistance:223.0];

Anchor and distance are not exposed by CCPhysicsJoint nor CCPhysicsDistanceJoint. You'd have to use the private constraint property to access the joint properties in the private ChipmunkConstraint class.

So one of these solutions would work:

  • the CCPhysicsJoint subclasses need to be public, and the subclasses exposing their initialization properties (readonly)
  • an existing, invalidated joint needs a "validate" method that adds it back in the physics simulation
  • Ideally both solutions. Re-validating joints would be super convenient, but you still have the cases where you need to alter the joint's settings, ie increasing its min/max distance based on game logic.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions