q5play
    Preparing search index...

    Class SliderJoint

    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 damping(): number

      Damping ratio, 0-1. Higher values reduce oscillation faster.

      Returns number

      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 energy(): number

      The current sliding speed of the joint.

      Returns number

    • 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 limitsEnabled(): boolean

      Whether the joint's translation limits are enabled.

      Returns boolean

      false
      
    • set limitsEnabled(val: boolean): void

      Parameters

      • val: boolean

      Returns void

    • get lowerLimit(): number

      The mathematical lower limit of translation.

      Returns number

    • get maxPower(): number

      Maximum force the motor can apply.

      Returns number

      10
      
    • set maxPower(val: number): void

      Parameters

      • val: number

      Returns void

    • get motorEnabled(): boolean

      Whether the joint's motor is enabled.

      Returns boolean

      true
      
    • 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.

      Returns number

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

      Accepts a number to set a symmetric range or an array with the lower and upper translation 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.

      Returns boolean

      false
      
    • 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

    • get translation(): number

      The current displacement of spriteB along the slide axis.

      Returns number

    • get upperLimit(): number

      The mathematical upper limit of translation.

      Returns number

    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