MV DrawCharacter Walking in Custom Window

Final Fantasy 1 Crystal Window


Here's the code i made from the gold window . My problems are:

1. When i first open the scene menu, its blank. the second time i open, it shows the crystal images. update function solved it
2. The walking sprites don't walk. I want them animated. Got solution from SRD plugin, credits to him

How can i correct them? thank you

I tried looking for what makes the walk character have walking/ stepping animation, but did not find it.

JavaScript:
(function() {
    
    var _Scene_Menu_new = Scene_Menu.prototype.create;
    Scene_Menu.prototype.create = function() {
        _Scene_Menu_new.call(this);
        this._statusWindow.x = this._commandWindow.width;
        this._statusWindow.y = 0;
        this.createCrystalWindow();
        this._crystalWindow.x = 0;
        this._crystalWindow.width = this._commandWindow.width;
        this._crystalWindow.y = Graphics.boxHeight - 300;
    };
     
    Scene_Menu.prototype.createCrystalWindow = function() {
        this._crystalWindow = new Window_Crystal(0, 0);
        this._crystalWindow.width = this._commandWindow.width;
        this._crystalWindow.x = 0;
        this._crystalWindow.y = Graphics.boxHeight - 300;
        this.addWindow(this._crystalWindow);
    };
   
    // credit SRD for this function
    Window_Base.prototype.drawCharacterAnimated = function(characterName, characterIndex, x, y, width, height, frame) {
        var bitmap = ImageManager.loadCharacter(characterName);
        var big = ImageManager.isBigCharacter(characterName);
        var pw = bitmap.width / (big ? 3 : 12);
        var ph = bitmap.height / (big ? 4 : 8);
        var n = characterIndex;
        var sx = ((n % 4 * 3 + 1) * pw) + (frame * 48);
        var sy = ((Math.floor(n / 4) * 4) * ph);
        this.contents.blt(bitmap, sx, sy, pw, ph, x - pw / 2, y - ph, width, height);
    };
           
    // Crystal window   
    function Window_Crystal() {
        this.initialize.apply(this, arguments);
    }
  
    Window_Crystal.prototype = Object.create(Window_Base.prototype);
    Window_Crystal.prototype.constructor = Window_Crystal;
  
    Window_Crystal.prototype.initialize = function(x, y) {
        var width = this.windowWidth();
        var height = this.windowHeight();       
        this._tick = 0;
        this._frame = 0;
        Window_Base.prototype.initialize.call(this, x, y, width, height);
        this.refresh();
    };
  
    // make same size as gold window
    Window_Crystal.prototype.windowWidth = function() {
        return 240;
    };
  
    Window_Crystal.prototype.windowHeight = function() {
        return this.fittingHeight(3);
    };
      
    Window_Crystal.prototype.refresh = function() {
        // characterName, characterIndex, x, y, width, height, frame
       
        // need to set frame to update
        var frame = (this._frame === 2) ? 0 : this._frame;   
        // Fire red crystal
        if (!$gameParty.hasItem($dataItems[101])) {
            this.drawCharacterAnimated("!Crystal", 5, 48 * 0 + 32, 96 + 16, 48, 96, frame);
        } else {
            this.drawCharacterAnimated("!Crystal", 0, 48 * 0 + 32, 96 + 16, 48, 96, frame);
        }

        // Earth yellow crystal
        if (!$gameParty.hasItem($dataItems[102])) {
            this.drawCharacterAnimated("!Crystal", 5, 48 * 1 + 32, 96 + 16, 48, 96, frame);
        } else {
            this.drawCharacterAnimated("!Crystal", 1, 48 * 1 + 32, 96 + 16, 48, 96, frame);
        }

        // Wind green crystal
        if (!$gameParty.hasItem($dataItems[103])) {
            this.drawCharacterAnimated("!Crystal", 5, 48 * 2 + 32, 96 + 16, 48, 96, frame);
        } else {
            this.drawCharacterAnimated("!Crystal", 2, 48 * 2 + 32, 96 + 16, 48, 96, frame);
        }

        // Water blue crystal
        if (!$gameParty.hasItem($dataItems[104])) {
            this.drawCharacterAnimated("!Crystal", 5, 48 * 3 + 32, 96 + 16, 48, 96, frame);
        } else {
            this.drawCharacterAnimated("!Crystal", 3, 48 * 3 + 32, 96 + 16, 48, 96, frame);
        }
    };
   
    // for crystal animation
    Window_Crystal.prototype.update = function() {
            this._tick += 1;
            if(this._tick >= 20) {
                this._frame += 1;
                if(this._frame > 2) this._frame = -1;
                this.refresh();
                this._tick = 0;
            }
        };
  
    Window_Crystal.prototype.open = function() {
        this.refresh();
        Window_Base.prototype.open.call(this);
    };
})();

I made a custom window! wow!
Thread closed

Original thread: https://forums.rpgmakerweb.com/threads/drawcharacter-walking-in-custom-window.157173/