I have a npc class which has a method called chase that is referenced inside the update function. when chase is called it says its not a function or it's not defined. I have another method being referenced in the same way that works.
chase()
{
this.Phaser.Physics.moveToObject(NPC_spr, player_spr, 100);
this.anims.play('NPC',true);
}
chase method in npcClass.js
bullet_ary = bulletGroup.getChildren();
for (let bullet_spr of bullet_ary)
{
bullet_spr.updateMe();
}
NPC_ary = npcGroup.getChildren()
for (let npc_spr of NPC_ary)
{
npc_spr.chase();
}
chase is called at npc_spr.chase(); which is in the update function, this creates an error while above the bullet_spr.updateMe() works. updateMe is also a method.
what I expected to happen was for the method to be called like the one above for the bullets. I have tried many different ways of rewriting it but everything results in the not defined or not a function error.
Error in console - Uncaught TypeError: npc_spr.chase is not a function
npcGroup code
npcGroup = this.add.group({key: 'NPC'});
npcGroup.createMultiple({key: 'NPC', repeat: 10 })
npcGroup.children.iterate(function(child)
{
child.setPosition(Phaser.Math.Between(0, config.height, 0), Phaser.Math.Between(0, config.width, 0));
})
I think the problem is that you are creating simple "Sprite" GameObjects and not from you Custom NPC class (except if you built a custom plugin, that adds that functionality). Since the group create function should create usually only sprite GameObject, if you don't define the
classType.So the solution would have to be, simply alter this line:
too look like this:
Then the error should disappear.
Here a short working Demo:
(showcasing the difference between "custom class group" and "sprite group")
The custom sprite rotates.