MZ How to change a picture when the mouse is hovering over it?

Using pictures for buttons. Want to change there appearance when hovered over
There are two parts to this:
  • How to change the appearance (event or script call?)
    Spoiler: How
    If your choice of "changed appearance" is offered by event commands, e.g. Show Picture or Tint Picture, then I assume there's no problem. 😮‍💨

    If you need a script, maybe specify exactly what effect you'd like. Note that you can look up various event commands in rmmz_objects.js, found in your project's js folder. For example, searching for Tint Picture locates this chunk of code:
    Spoiler: Tint Picture command code (rmmz_objects.js)
    JavaScript:
    // Tint Picture
    Game_Interpreter.prototype.command234 = function(params) {
        $gameScreen.tintPicture(params[0], params[1], params[2]);
        if (params[3]) {
            this.wait(params[2]);
        }
        return true;
    };
    You can then search for tintPicture to figure out what inputs it requires, etc...
    Spoiler: Game_Screen > tintPicture (rmmz_objects.js)
    JavaScript:
    Game_Screen.prototype.tintPicture = function(pictureId, tone, duration) {
        const picture = this.picture(pictureId);
        if (picture) {
            picture.tint(tone, duration);
        }
    };
    In this case, tone is an array of four values: red, green, blue, grey. This is just as an example, e.g. maybe you'd want to use showPicture instead, to swap out the image. Check out the "When" spoiler for script examples~
  • When to change the appearance
    Spoiler: When
    Unless you want to run a parallel event and check the cursor coordinates every (few) frame(s), I think you'll need two things for this:
    • An "on enter trigger", for when the cursor moves onto the picture.
    • An "on leave trigger", for when the cursor moves off of the picture.
    By default these are represented by the onMouseEnter and onMouseExit methods. In case you're interested, I have a plugin called Cae_PictureTouch that lets you bind a script or common event to these using Plugin Commands, e.g.
    • Highlight "this picture" on enter (6-frame fade time):
      JavaScript:
      $gameScreen.tintPicture(pictureId, [64,64,64,0], 6);
    • Reset tint of "this picture" on leave (6-frame fade time):
      JavaScript:
      $gameScreen.tintPicture(pictureId, null, 6);
    An alternative is to alias them yourself, e.g.
    Spoiler: Simple all-picture highlight plugin suggestion
    JavaScript:
    (alias => {
      Sprite_Picture.prototype.onMouseEnter = function() {
        alias.apply(this, arguments);
        const hoverTone = [64, 64, 64, 0];
        const duration = 6;  // 0.1 seconds transition time
        this.picture()?.tint(hoverTone, duration);
      };
    })(Sprite_Picture.prototype.onMouseEnter);
    
    (alias => {
      Sprite_Picture.prototype.onMouseExit = function() {
        alias.apply(this, arguments);
        const leaveTone = null;  // no tone, i.e. reset
        const duration = 6;  // 0.1 seconds transition time
        this.picture()?.tint(leaveTone, duration);
      };
    })(Sprite_Picture.prototype.onMouseExit);

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/how-to-change-a-picture-when-the-mouse-is-hovering-over-it.128408/