Home > database >  Phaser 3: Add extra Frame to Animation
Phaser 3: Add extra Frame to Animation

Time:03-08

I have an animation for which I generate my frames with generateFrameNames. However as the last frame I need to add a frame with an entirely different Prefix. Is there any way I can generate my frames using this method, and then "add" the last frame extra? How would I do that?

Currently my code looks like this:

this.anims.create({
        key: "nom",
        frameRate: 12,
        frames: this.anims.generateFrameNames("chara", {
            prefix: "nom_000",
            start: 0,
            end: 5}),
        repeat: 2,
    });

The frame I need to add is in the same Spritesheet and is called idle_0000.

CodePudding user response:

Well you could use the function addFrame (documentation), just:

Caution: you have to pass an Array, I tried to pass a single frame, and this doesn't work and doesn't through an error.

let animToAlter = this.anims.create({
    key: "nom",
    frameRate: 12,
    frames: this.anims.generateFrameNames("chara", {
        prefix: "nom_000",
        start: 0,
        end: 5}).,
    repeat: 2,
});

// this call could be optimized, but for demo it should work
animToAlter.addFrame(this.anims.generateFrameNames('chara', { prefix: 'idle_000', start: 0, end: 0 }));
  • Related