staticBody class with Arcade?

Hi,

I’m searching to make a static class of an object.

No problem with a simple sprite :

class Arcade extends Phaser.Physics.Arcade.Sprite {
	constructor(scene, x, y, texture) {
		super(scene, x, y, texture)
		scene.add.existing(this)
		scene.physics.add.existing(this)
	}
} 

but for a static object like :
atari = this.physics.add.staticImage(400, 300, 'atari');

this code don’t woks :

class Static extends Phaser.Physics.Arcade.StaticImage {
	constructor(scene, x, y, texture) {
		super(scene, x, y, texture)
		scene.add.existing(this)
		scene.physics.add.existing(this)
	}
} 

How do you do to create a class with a static Image ?

Thanks

Hi @espace,
The existing method of Arcade.Factory has an optional second param isStatic for this purpose.
More info in the docs

Regards.

1 Like

Sorry but i don’t understand, i try this :

class Static extends Phaser.Physics.Arcade.Factory {
	constructor(scene, x, y, texture) {
		super(scene, x, y, texture)
		this.isStatic = true
		scene.add.existing(this)
		scene.physics.add.existing(this)
	}
}

but it doens’t works.

Don’t worry @espace .
The Arcade.Factory object is the same as the add property of the physics plugin.
In a nutshell, what I wanted to say was this:

scene.physics.add.existing(this, true) // Adds static body
scene.physics.add.existing(this, false) // Adds dynamic body (default)

Regards.