Changes to GroupConfig in 3.16.1

I am updating my game from phaser 3.15.1 to 3.16.1 and I am having some issues with groups as pools. I’m not completely understanding the api documentation on the changes to GroupConfig.

The classType config property now takes a GroupClassTypeConstructor, but when I look at the api documentation I’m not sure what this function should do. Before I just had the class of the object that the pool would instantiate.

When I look in the examples it is still using 3.15.1 and works the same my code worked before I went to 3.16.1.

Just wondering if anyone had some info on what should really go into the classType config parameter in 3.16.1.

Thank you.

1 Like

classType works the same before, it’s just the type description changed a bit. A class is a constructor, so you can pass your class. The default value is Phaser.GameObjects.Sprite.

Are you getting an error running your code?

I am. The class I have worked in 3.15.1. It inherits from a base class of mine that then inherits from Sprite. This one is a typescript one. A few others caused a web pack compile error. This may be because I didn’t implement the full constructor in my super classes. But typescript still complains. If I change the following to use as any, it compiles. I didn’t get a chance to actually try it yet.

   this.trashPool = this.add.group({
        maxSize: 20,
        defaultKey: 'ODImages',
        defaultFrame: 'trashcollection-000.png',
        classType: ODTrash as any,                            <-------    It compiles like this
        createCallback: (trash:ODTrash)=>{},
        removeCallback: (trash:ODTrash)=>{},
        runChildUpdate: false
    });

Argument of type ‘{ maxSize: number; defaultKey: string; defaultFrame: string; classType: typeof ODTrash; createCallback:
(trash: ODTrash) => void; removeCallback: (trash: ODTrash) => void; runChildUpdate: false; }’ is not assignable to parameter of type ‘GameObject[] | GroupConfig | GroupConfig[]’.
Type ‘{ maxSize: number; defaultKey: string; defaultFrame: string; classType: typeof ODTrash; createCallback: (trash: ODTrash) => void; removeCallback: (trash: ODTrash) => void; runChildUpdate: false; }’ is not assignable to type ‘GroupConfig’.
Types of property ‘classType’ are incompatible.
Type ‘typeof ODTrash’ is not assignable to type ‘GroupClassTypeConstructor’.
Type ‘typeof ODTrash’ provides no match for the signature ‘(scene: Scene, x: number, y: number, texture: string, frame?: string | number): void’.ts(2345)

Everything works if I change all of the classType to something as follows:

classType: ODTrashMarker as any

Webpack works and the game functions properly but I couldn’t get it to work without marking the class as any.

This is the important part. Your constructor must include (scene, x, y, texture, frame) because Phaser will call it with those arguments if the group creates a game object.

My constructors for all my custom classes have the constructor signature. Maybe it’s just the typescript def file, because if I mark it as any so everything works just like it did in 3.15.1. Now I upgraded to 3.16.2 and its still complains if I don’t mark it as any.

The constructors look correct to me and it all works when the game is running.

I also noticed that if I use the type Phaser.GameObjects.Sprite, which is supposed to be the default, it still complains, which is why it seems like a typescript def issue.