q5play
    Preparing search index...

    Class DistanceJoint

    A Joint is used to constrain the movement of two sprites relative to each other, which can lead to nuanced physics interactions.

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    The Box2D joint ID. Don't change it!

    spriteA: Sprite

    The first sprite in the joint.

    spriteB: Sprite

    The second sprite in the joint.

    type: string

    The type of joint. Can be one of:

    "glue", "distance", "wheel", "hinge", "slider", or "grabber".

    Can't be changed after the joint is created.

    visible: boolean

    Determines whether to draw the joint if spriteA or spriteB is drawn.

    true
    

    Accessors

    • get collideConnected(): boolean

      Set to true if you want the joint's sprites to collide with each other.

      Returns boolean

      false
      
    • set collideConnected(val: boolean): void

      Parameters

      • val: boolean

      Returns void

    • get currentLength(): number

      The current distance between the two joint anchors.

      Returns number

    • get damping(): number

      Damping is a 0-1 ratio describing how quickly the joint loses vibrational energy.

      0.0 means no damping, 1.0 means critical damping, which will stop the joint from vibrating at all.

      Damping only effects joints that have a springiness greater than 0.

      Returns number

      0.0
      
    • set damping(val: number): void

      Parameters

      • val: number

      Returns void

    • get draw(): Function

      Function that draws the joint. Can be overridden by the user.

      Returns Function

    • set draw(val: Function): void

      Parameters

      • val: Function

      Returns void

    • get forceThreshold(): number

      The amount of force that must be applied to the joint before it breaks.

      Setting the threshold too high leads to instability. Use sprite.addCollider to simulate unbreakable bonds between shapes.

      Returns number

      500
      
    • set forceThreshold(val: number): void

      Parameters

      • val: number

      Returns void

    • get length(): number

      The target length of the joint between the two joint anchors.

      It's set to the current distance between the two sprites when the joint is created.

      Returns number

    • set length(val: number): void

      Parameters

      • val: number

      Returns void

    • get limitsEnabled(): boolean

      Whether the joint's length limits are enabled. When enabled a min/max length range constrains the joint.

      Returns boolean

      false
      
    • set limitsEnabled(val: boolean): void

      Parameters

      • val: boolean

      Returns void

    • get maxLength(): number

      The maximum length allowed when limits are enabled.

      Returns number

    • get maxPower(): number

      Maximum motor force the motor can apply.

      Returns number

    • set maxPower(val: number): void

      Parameters

      • val: number

      Returns void

    • get minLength(): number

      The minimum length allowed when limits are enabled.

      Returns number

    • get motorEnabled(): boolean

      Whether the joint's motor is enabled.

      Returns boolean

      false
      
    • set motorEnabled(val: boolean): void

      Parameters

      • val: boolean

      Returns void

    • get offsetA(): Vector

      Offset to the joint's anchorA position from the center of spriteA.

      Only distance and hinge joints have an offsetA.

      Returns Vector

      {x: 0, y: 0}
      
    • set offsetA(val: [] | Vector | { x: number; y: number }): void

      Parameters

      • val: [] | Vector | { x: number; y: number }

      Returns void

    • get offsetB(): Vector

      Offset to the joint's anchorB position from the center of spriteB.

      Only distance, hinge, and wheel joints have an offsetB.

      Returns Vector

      {x: 0, y: 0}
      
    • set offsetB(val: [] | Vector | { x: number; y: number }): void

      Parameters

      • val: [] | Vector | { x: number; y: number }

      Returns void

    • get power(): number

      The current motor force being applied by the joint.

      Returns number

    • set range(val: number | [number, number]): void

      Accepts a number to set a symmetric range or an array with the minimum and maximum length limits.

      Parameters

      • val: number | [number, number]

      Returns void

    • get reactionForce(): any

      How much force the joint is applying to keep the two sprites together.

      Returns any

    • get reactionTorque(): any

      How much torque the joint is applying to keep the two sprites together.

      Returns any

    • get speed(): number

      Motor speed.

      Returns number

      0
      
    • set speed(val: number): void

      Parameters

      • val: number

      Returns void

    • get springEnabled(): boolean

      Whether spring behavior is enabled for the joint.

      Returns boolean

      true
      
    • set springEnabled(val: boolean): void

      Parameters

      • val: boolean

      Returns void

    • get springiness(): number

      The springiness of the joint, a 0-1 ratio.

      0 is rigid, 0.5 is bouncy, 1 is loose.

      Returns number

      0
      
    • set springiness(val: number): void

      Parameters

      • val: number

      Returns void

    • get torqueThreshold(): number

      The amount of torque that must be applied to the joint before it breaks.

      Setting the threshold too high leads to instability. Use sprite.addCollider to simulate unbreakable bonds between shapes.

      Returns number

      500
      
    • set torqueThreshold(val: number): void

      Parameters

      • val: number

      Returns void

    Methods

    • Deletes the joint from the world and from each of the associated sprites' joints arrays.

      Returns void

    • This function is run when the joint's reaction force exceeds the force threshold or its reaction torque exceeds the torque threshold.

      By default, the sprites' speed and rotation speed are set to 0 and the joint is deleted, simulating a break.

      Returns void