Texture.frame missing

friends, please help, the loaded frames suddenly began to be lost. in my game, I reuse created objects with new attributes, including random frames. and then they suddenly began to disappear at the setFrame stage. What could be causing this? here is my code:

export default class MovableObject extends Phaser.GameObjects.Sprite {
    constructor(data) {
        super(data.scene, data.x, data.y, data.frame)
        this.init(data)
    }
    init(data) {
        this.scene.add.existing(this) 
        this.scene.physics.add.existing(this) 
        this.body.enable = true 
    }
    update() {
        if (this.active && this.isDead()) { 
            this.setAlive(false)
        }
    }
    setAlive(status) { 
        this.body.enable = status 
        this.setVisible(status) 
        this.setActive(status) 
    }
    reset(x, y) {
        this.x = x 
        this.y = y
        this.setAlive(true)
    }
    isDead() {
        return false
    }
    move() {
        this.body.setVelocityY(OBJECTS_VELOCITY)
    }
    static generateСoordinates() { 
        this.lastX = [this.lastX_N, this.lastX_P]
        let x = Phaser.Math.Between(300, 900) 
        for (let i in this.lastX) {
            if (x - SPRITE_WIDTH < this.lastX[i] && x + SPRITE_WIDTH > this.lastX[i]) x = Phaser.Math.Between(300, 900)
        }
        return x
    }
}
export default class NegativeObject extends MovableObject {

    static generateAttributes() {
        let x = super.generateСoordinates()
        const y = Y_position
        return { x, y, frame: `rock0${Phaser.Math.Between(1, 3)}` }
    }
    static generate(scene) {
        const data = NegativeObject.generateAttributes()
        return new NegativeObject({
            scene,
            x: data.x,
            y: data.y,
            frame: data.frame,
        })
    }
    init(data) {
        super.init(data)
    }
    reset() {
        const data = NegativeObject.generateAttributes()
        super.reset(data.x, data.y)
        this.setFrame(data.frame)
    }
    isDead() { // проверка на выход за пределы экрана
        return this.y > HEIGHT
    }
}

[image]

[image]

:wave:

You may be confusing texture and frame arguments. In

super(data.scene, data.x, data.y, data.frame)

data.frame is passed as the texture argument. But in

this.setFrame(data.frame)

it’s used as frame.

1 Like

many thanks. I replaced setFrame with setTexture and everything worked as it should!

[image]