Container of Sprites cannot generate frames

I’m pretty new to phaser, so let me know if I’m approaching this all wrong.

I want to allow players to have customizable characters, which I would make by placing a series of sprites inside a container.

The class PlayableChar extends the container gameobject class

export default class PlayableChar extends Phaser.GameObjects.Container {
    constructor (data) {
        //set data object to 
        let {scene,x,y,bodyModel,bodyColor} = data;
        let children = [];
        let parts = PlayableChar.partsList(bodyModel,bodyColor);
        for (let p = 0; p < parts.length; p++) {
            children[p] = new Phaser.GameObjects.Sprite(scene, 0, 0, `${parts[p].type}_${parts[p].model}_${parts[p].color}`,0)
        scene.add.existing(this), 0);
        this.bodyModel = bodyModel;
        this.bodyColor = bodyColor;


    static partsList(bodyModel,bodyColor) {
        return [{type:'frontLimbs',model:"general",color:bodyColor},{type:'body',model:bodyModel,color:bodyColor},{type:'backLimbs',model:"general",color:bodyColor}];
    //load all the assets and animations
    static preload(data) {
        let {scene,bodyModel,bodyColor} = data;
        console.log(`bodyModel = ${bodyModel} bodyColor = ${bodyColor}`)
        //load all parts
        let parts = PlayableChar.partsList(bodyModel,bodyColor);
        for (let p = 0; p < parts.length; p++) {
            const loadPart = parts[p];
            let partKey = `${loadPart.type}_${loadPart.model}_${loadPart.color}`;
                key: `${partKey}_idle`, 
                repeat: -1,
                frameRate: 12,
                frames: partKey //There I'm just straight up load the whole spritesheet. But I've tried everything, getFramesByNumbers, passing frame objects, etc.


In my main scene I can preload like this

this.bodyColor = "teal";
this.bodyModel = "quark";

and instantiate like this (in create method)

this.player = new Player({scene:this,x:330,y:330,bodyModel:this.bodyModel,bodyColor:this.bodyColor});

And that works as expected
But I get an error here

//Uncaught TypeError: Cannot read properties of undefined (reading 'frame')

And when I console.log the scene, I find the list of animations all have frames with empty arrays.

What’s wrong? and more importantly, how can I accopmlish the goal of loading animatable spritesheets in a container (or any sort of group)


You can’t use the partKey texture in anims.create() until the texture is loaded/added.

Use the loader complete event, or use a static create() method that you call from scene create().

Thanks I realized that now. My mistake.

Also for some reason, I have to use scene.add.sprite instead of this new Phaser.GameObjects.Sprite or the animations don’t show. Not sure why, but I found the solution.

You can also use

children[p] = new Phaser.GameObjects.Sprite(scene, 0, 0, `${parts[p].type}_${parts[p].model}_${parts[p].color}`, 0)