q5play
    Preparing search index...

    Class World

    The World is the Box2D physics simulation.

    Index

    Constructors

    Properties

    autoStep: boolean
    true
    
    meterSize: number

    Represents the size of a meter in pixels.

    Adjusting this property changes the simulated scale of the physics world. For optimal results, it should be set such that sprites are between 0.1 and 10 meters in size in the physics simulation.

    The default value is 60, which means that your sprites should optimally be between 6 and 600 pixels in size.

    60
    
    physicsTime: number

    The time elapsed in the physics simulation in seconds.

    subSteps: number

    The number of sub-steps per physics update. More sub-steps increases accuracy at the cost of performance.

    4
    

    The Box2D world ID. Don't change it!

    Accessors

    • get allowSleeping(): boolean

      "Sleeping" sprites get temporarily ignored during physics simulation. A sprite starts "sleeping" when it stops moving and doesn't collide with anything that it wasn't already touching.

      This is an important performance optimization that you probably shouldn't disable for every sprite in the world.

      Returns boolean

      true
      
    • set allowSleeping(val: boolean): void

      Parameters

      • val: boolean

      Returns void

    • get awakeBodies(): number

      The number of physics bodies currently awake in the world.

      Returns number

    • get bounceThreshold(): number

      The lowest velocity an object can have before it is considered to be at rest.

      Adjust the bounce threshold to allow for slow moving objects but don't have it be too low, or else objects will never sleep, which will hurt performance.

      Returns number

      0.19
      
    • set bounceThreshold(val: number): void

      Parameters

      • val: number

      Returns void

    • get debugInfo(): any

      Box2D world counter/statistics data.

      Returns any

    • get gravity(): any

      Gravity force vector that affects all dynamic physics colliders.

      Returns any

      { x: 0, y: 0 }
      
    • set gravity(val: any): void

      Parameters

      • val: any

      Returns void

    • get hitThreshold(): number

      The minimum impact velocity needed for a hit event to be fired.

      Returns number

    • set hitThreshold(val: number): void

      Parameters

      • val: number

      Returns void

    • get profile(): any

      Box2D world performance profile data.

      Returns any

    • get realTime(): number

      The real time in seconds since the world was created, including time spent paused.

      Returns number

    • get timeScale(): number

      A time scale of 1.0 represents real time. Accepts decimal values between 0 and 2.

      Returns number

      1.0
      
    • set timeScale(val: number): void

      Parameters

      • val: number

      Returns void

    • get updateRate(): number

      The fixed update rate of the physics simulation in hertz.

      The time step, the amount of time that passes during a physics update, is calculated to be: 1 / updateRate * timeScale

      Setting the update rate to a value lower than 50hz is not recommended, as simulation quality will degrade.

      Returns number

      60
      
    • set updateRate(val: number): void

      Parameters

      • val: number

      Returns void

    Methods

    • Finds the first sprite (with a physics body) that intersects a swept circle (capsule cast) from startPos to endPos.

      Parameters

      • startPos: number[] | { x: number; y: number }

        starting position of the cast, object with x and y properties or array [x, y]

      • endPos: number[] | { x: number; y: number }

        end position of the cast

      • radius: number

        radius of the circle

      Returns Sprite

      The first sprite hit or undefined

    • Finds all sprites (with physics bodies) that intersect a swept circle (capsule cast) from startPos to endPos, sorted by distance.

      Parameters

      • startPos: number[] | { x: number; y: number }

        starting position of the cast

      • endPos: number[] | { x: number; y: number }

        end position of the cast

      • radius: number

        radius of the circle

      • Optionallimiter: Function

        callback run each time the cast hits a sprite; return true to stop the cast

      Returns Sprite[]

      An array of sprites hit, sorted by distance.

    • Applies an explosive force to sprites within the radius of the explosion.

      Parameters

      • x: number

        x coordinate or object with x and y properties of the center of the explosion

      • y: number
      • Optionalradius: number

        the distance from the center of the explosion that sprites can be affected by the explosion

      • Optionalmagnitude: number

        the strength of the explosion force, default is 1

      • Optionalfalloff: number

        how much the explosion force decreases as sprites are farther from the center of the explosion, default is 0.1 (10% decrease per pixel)

      Returns void

    • Applies an explosive force to sprites within the radius of the explosion.

      Parameters

      • pos: { x: number; y: number }
      • Optionalradius: number

        the distance from the center of the explosion that sprites can be affected by the explosion

      • Optionalmagnitude: number

        the strength of the explosion force, default is 1

      • Optionalfalloff: number

        how much the explosion force decreases as sprites are farther from the center of the explosion, default is 0.1 (10% decrease per pixel)

      Returns void

    • Returns the sprite at the specified position on the top most layer, drawn when the camera was on.

      The sprite must have a physics body to be detected.

      Parameters

      • x: number

        x coordinate or object with x and y properties

      • y: number
      • Optionalradius: number

        the distance from the point that sprites can be detected at, default is 0 (only sprites that overlap the point will be detected)

      • Optionalgroup: Group

        the group to search

      Returns Sprite

      a sprite

    • Returns the sprite at the specified position on the top most layer, drawn when the camera was on.

      The sprite must have a physics body to be detected.

      Parameters

      • pos: { x: number; y: number }

        object with x and y properties

      • Optionalradius: number

        the distance from the point that sprites can be detected at, default is 0 (only sprites that overlap the point will be detected)

      • Optionalgroup: Group

        the group to search

      Returns Sprite

      a sprite

    • Returns the sprites at a position, ordered by layer.

      Sprites must have a physics body to be detected.

      Parameters

      • x: number

        x coordinate or object with x and y properties

      • y: number
      • Optionalradius: number

        the distance from the point that sprites can be detected at, default is 0 (only sprites that overlap the point will be detected)

      • Optionalgroup: Group

        limit results to a specific group, allSprites by default

      • OptionalcameraActiveWhenDrawn: boolean

        limit results to sprites drawn when the camera was active, true by default

      Returns Sprite[]

      an array of sprites

    • Returns the sprites at a position, ordered by layer.

      Sprites must have a physics body to be detected.

      Parameters

      • pos: { x: number; y: number }

        object with x and y properties

      • Optionalradius: number

        the distance from the point that sprites can be detected at, default is 0 (only sprites that overlap the point will be detected)

      • Optionalgroup: Group

        limit results to a specific group, allSprites by default

      • OptionalcameraActiveWhenDrawn: boolean

        limit results to sprites drawn when the camera was active, true by default

      Returns Sprite[]

      an array of sprites

    • Performs a physics simulation step that advances all sprites forward in time by 1 / updateRate * timeScale if no timeStep is given.

      Parameters

      • OptionaltimeStep: number

      Returns void

    • Finds the first sprite (with a physics body) that intersects a ray (line).

      Parameters

      • startPos: number[] | { x: number; y: number }

        starting position of the ray cast, object with x and y properties or array [x, y]

      • direction: number

        direction angle of the ray

      • OptionalmaxDistance: number

        max distance the ray should check, default 10000

      Returns Sprite

      The first sprite the ray hits or undefined

    • Finds the first sprite (with a physics body) that intersects a ray from startPos to endPos.

      Parameters

      • startPos: number[] | { x: number; y: number }

        starting position of the ray cast

      • endPos: number[] | { x: number; y: number }

        end position of the ray cast

      Returns Sprite

      The first sprite the ray hits or undefined

    • Finds all sprites (with physics bodies) that intersect a ray (line), sorted by distance.

      Parameters

      • startPos: number[] | { x: number; y: number }

        starting position of the ray cast, object with x and y properties or array [x, y]

      • direction: number

        direction angle of the ray

      • OptionalmaxDistance: number

        max distance the ray should check, default 10000

      • Optionallimiter: Function

        callback run each time the ray hits a sprite; return true to stop the ray

      Returns Sprite[]

      An array of sprites that the ray cast hit, sorted by distance. The sprite closest to the starting point will be at index 0. If a limiter is provided, this array includes the sprite that caused the ray to stop.

    • Finds all sprites (with physics bodies) that intersect a ray from startPos to endPos, sorted by distance.

      Parameters

      • startPos: number[] | { x: number; y: number }

        starting position of the ray cast

      • endPos: number[] | { x: number; y: number }

        end position of the ray cast

      • Optionallimiter: Function

        callback run each time the ray hits a sprite; return true to stop the ray

      Returns Sprite[]

      An array of sprites that the ray cast hit, sorted by distance.

    • Alias for physicsUpdate.

      Parameters

      • OptionaltimeStep: number

      Returns void