Running multiple update methods?


#1

If I had code structured like in the example below, shouldn’t the update() method from the Child class execute on update() of the Scene?

class ParentClass extends Phaser.Physics.Arcade.Sprite {
	constructor (a)
	{
		super(a);
		scene.sys.updateList.add(this);
		//stuff
	}
	//more stuff
}
class Child extends Parent {
	constructor (b)
	{
		super(b);
		//stuff
	}

	update (time, delta)
	{
		console.log('Updating!');
		//more stuff
	}
}
class Scene extends Phaser.Scene {
	//all the other stuff
	create ()
	{
		let c = true;
		this.obj = new Child(c);
	}
	update (time, delta)
	{
		//nothing
	}
}

#2

No, you have to call the update method manually. Also beware of multiple inheritance.

//if you're the child and you want to call parent update function, it's super.update()

//Inside a scene
//create

//you may have to attach it to the scene with "this" keyword (this.p) to access it in the update method.

let p = new Parent();
let c = new Child();

//update
p.update();

c.update();


#3

Gotcha–Thank you for replying!