Skip to main content
Version: Phaser v4.0.0-rc.6

Factory

The Arcade Physics Factory allows you to easily create Arcade Physics enabled Game Objects.

Objects that are created by this Factory are automatically added to the physics world.

Constructor

new Factory(world)

Parameters

nametypeoptionaldescription
worldPhaser.Physics.Arcade.WorldNoThe Arcade Physics World instance.

Scope: static

Source: src/physics/arcade/Factory.js#L16
Since: 3.0.0

Public Members

scene

scene: Phaser.Scene

Description:

A reference to the Scene this Arcade Physics instance belongs to.

Source: src/physics/arcade/Factory.js#L43
Since: 3.0.0


sys

sys: Phaser.Scenes.Systems

Description:

A reference to the Scene.Systems this Arcade Physics instance belongs to.

Source: src/physics/arcade/Factory.js#L52
Since: 3.0.0


world

world: Phaser.Physics.Arcade.World

Description:

A reference to the Arcade Physics World.

Source: src/physics/arcade/Factory.js#L34
Since: 3.0.0


Public Methods

body

<instance> body(x, y, [width], [height])

Description:

Creates a new physics Body with the given position and size.

This Body is not associated with any Game Object, but still exists within the world

and can be tested for collision, have velocity, etc.

Parameters:

nametypeoptionaldefaultdescription
xnumberNoThe horizontal position of this Body in the physics world.
ynumberNoThe vertical position of this Body in the physics world.
widthnumberYes64The width of the Body in pixels. Cannot be negative or zero.
heightnumberYes64The height of the Body in pixels. Cannot be negative or zero.

Returns: Phaser.Physics.Arcade.Body - The Body that was created.

Source: src/physics/arcade/Factory.js#L254
Since: 3.60.0


collider

<instance> collider(object1, object2, [collideCallback], [processCallback], [callbackContext])

Description:

Creates a new Arcade Physics Collider object.

Parameters:

nametypeoptionaldescription
object1Phaser.Types.Physics.Arcade.ArcadeColliderTypeNoThe first object to check for collision.
object2Phaser.Types.Physics.Arcade.ArcadeColliderTypeNoThe second object to check for collision.
collideCallbackPhaser.Types.Physics.Arcade.ArcadePhysicsCallbackYesThe callback to invoke when the two objects collide.
processCallbackPhaser.Types.Physics.Arcade.ArcadePhysicsCallbackYesThe callback to invoke when the two objects collide. Must return a boolean.
callbackContext*YesThe scope in which to call the callbacks.

Returns: Phaser.Physics.Arcade.Collider - The Collider that was created.

Source: src/physics/arcade/Factory.js#L62
Since: 3.0.0


destroy

<instance> destroy()

Description:

Destroys this Factory.

Source: src/physics/arcade/Factory.js#L318
Since: 3.5.0


existing

<instance> existing(gameObject, [isStatic])

Description:

Adds an Arcade Physics Body to the given Game Object.

Tags:

  • generic

Parameters:

nametypeoptionaldefaultdescription
gameObjectPhaser.GameObjects.GameObjectNoA Game Object.
isStaticbooleanYesfalseCreate a Static body (true) or Dynamic body (false).

Returns: Phaser.Types.Physics.Arcade.GameObjectWithBody - The Game Object.

Source: src/physics/arcade/Factory.js#L100
Since: 3.0.0


group

<instance> group([children], [config])

Description:

Creates a Physics Group object.

All Game Objects created by this Group will automatically be dynamic Arcade Physics objects.

Parameters:

nametypeoptionaldescription
childrenArray.<Phaser.GameObjects.GameObject> | Phaser.Types.Physics.Arcade.PhysicsGroupConfigPhaser.Types.GameObjects.Group.GroupCreateConfigYes
configPhaser.Types.Physics.Arcade.PhysicsGroupConfig | Phaser.Types.GameObjects.Group.GroupCreateConfigYesSettings for this group.

Returns: Phaser.Physics.Arcade.Group - The Group object that was created.

Source: src/physics/arcade/Factory.js#L237
Since: 3.0.0


image

<instance> image(x, y, texture, [frame])

Description:

Creates a new Arcade Image object with a Dynamic body.

Parameters:

nametypeoptionaldescription
xnumberNoThe horizontal position of this Game Object in the world.
ynumberNoThe vertical position of this Game Object in the world.
texturestring | Phaser.Textures.TextureNoThe key, or instance of the Texture this Game Object will use to render with, as stored in the Texture Manager.
framestring | numberYesAn optional frame from the Texture this Game Object is rendering with.

Returns: Phaser.Types.Physics.Arcade.ImageWithDynamicBody - The Image object that was created.

Source: src/physics/arcade/Factory.js#L146
Since: 3.0.0


overlap

<instance> overlap(object1, object2, [collideCallback], [processCallback], [callbackContext])

Description:

Creates a new Arcade Physics Collider Overlap object.

Parameters:

nametypeoptionaldescription
object1Phaser.Types.Physics.Arcade.ArcadeColliderTypeNoThe first object to check for overlap.
object2Phaser.Types.Physics.Arcade.ArcadeColliderTypeNoThe second object to check for overlap.
collideCallbackPhaser.Types.Physics.Arcade.ArcadePhysicsCallbackYesThe callback to invoke when the two objects collide.
processCallbackPhaser.Types.Physics.Arcade.ArcadePhysicsCallbackYesThe callback to invoke when the two objects collide. Must return a boolean.
callbackContext*YesThe scope in which to call the callbacks.

Returns: Phaser.Physics.Arcade.Collider - The Collider that was created.

Source: src/physics/arcade/Factory.js#L81
Since: 3.0.0


sprite

<instance> sprite(x, y, key, [frame])

Description:

Creates a new Arcade Sprite object with a Dynamic body.

Parameters:

nametypeoptionaldescription
xnumberNoThe horizontal position of this Game Object in the world.
ynumberNoThe vertical position of this Game Object in the world.
keystringNoThe key of the Texture this Game Object will use to render with, as stored in the Texture Manager.
framestring | numberYesAn optional frame from the Texture this Game Object is rendering with.

Returns: Phaser.Types.Physics.Arcade.SpriteWithDynamicBody - The Sprite object that was created.

Source: src/physics/arcade/Factory.js#L195
Since: 3.0.0


staticBody

<instance> staticBody(x, y, [width], [height])

Description:

Creates a new static physics Body with the given position and size.

This Body is not associated with any Game Object, but still exists within the world

and can be tested for collision, etc.

Parameters:

nametypeoptionaldefaultdescription
xnumberNoThe horizontal position of this Body in the physics world.
ynumberNoThe vertical position of this Body in the physics world.
widthnumberYes64The width of the Body in pixels. Cannot be negative or zero.
heightnumberYes64The height of the Body in pixels. Cannot be negative or zero.

Returns: Phaser.Physics.Arcade.StaticBody - The Static Body that was created.

Source: src/physics/arcade/Factory.js#L286
Since: 3.60.0


staticGroup

<instance> staticGroup([children], [config])

Description:

Creates a Static Physics Group object.

All Game Objects created by this Group will automatically be static Arcade Physics objects.

Parameters:

nametypeoptionaldescription
childrenArray.<Phaser.GameObjects.GameObject> | Phaser.Types.GameObjects.Group.GroupConfigPhaser.Types.GameObjects.Group.GroupCreateConfigYes
configPhaser.Types.GameObjects.Group.GroupConfig | Phaser.Types.GameObjects.Group.GroupCreateConfigYesSettings for this group.

Returns: Phaser.Physics.Arcade.StaticGroup - The Static Group object that was created.

Source: src/physics/arcade/Factory.js#L220
Since: 3.0.0


staticImage

<instance> staticImage(x, y, texture, [frame])

Description:

Creates a new Arcade Image object with a Static body.

Parameters:

nametypeoptionaldescription
xnumberNoThe horizontal position of this Game Object in the world.
ynumberNoThe vertical position of this Game Object in the world.
texturestring | Phaser.Textures.TextureNoThe key, or instance of the Texture this Game Object will use to render with, as stored in the Texture Manager.
framestring | numberYesAn optional frame from the Texture this Game Object is rendering with.

Returns: Phaser.Types.Physics.Arcade.ImageWithStaticBody - The Image object that was created.

Source: src/physics/arcade/Factory.js#L122
Since: 3.0.0


staticSprite

<instance> staticSprite(x, y, texture, [frame])

Description:

Creates a new Arcade Sprite object with a Static body.

Parameters:

nametypeoptionaldescription
xnumberNoThe horizontal position of this Game Object in the world.
ynumberNoThe vertical position of this Game Object in the world.
texturestring | Phaser.Textures.TextureNoThe key, or instance of the Texture this Game Object will use to render with, as stored in the Texture Manager.
framestring | numberYesAn optional frame from the Texture this Game Object is rendering with.

Returns: Phaser.Types.Physics.Arcade.SpriteWithStaticBody - The Sprite object that was created.

Source: src/physics/arcade/Factory.js#L170
Since: 3.0.0