Mouseover as trigger

I created some buttons in my menu windows using Sprite_Button,
Scene_Status.prototype.createSpriteButtons = function() {
this._homeButton = new Sprite_Button();
this._homeButton.bitmap = ImageManager.loadPicture('home');
this.addChild(this._homeButton);
this._homeButton.x = Graphics.width / 2
this._homeButton.setClickHandler(this.popScene.bind(this));

this._nextButton = new Sprite_Button();
this._nextButton.bitmap = ImageManager.loadPicture('right');
this.addChild(this._nextButton);
this._nextButton.x = Graphics.width / 2 + 100
this._nextButton.setClickHandler(this.nextActor.bind(this));

this._prevButton = new Sprite_Button();
this._prevButton.bitmap = ImageManager.loadPicture('left');
this.addChild(this._prevButton);
this._prevButton.x = Graphics.width / 2 - 100
this._prevButton.setClickHandler(this.previousActor.bind(this));
};

I want the sprite buttons to change pictures when the mouse is hovering over how do I do that?
Well in principle that would be coded in the image objects (sprite or window btw? not sure what exactly is changing here). In that particular object's update method, you would have something checking if the mouse is over it or not, and if it's different than the current state, change to the next state (so refresh bitmap for sprite and refresh for window). This is one method to do it, but there are other methods.
Well in principle that would be coded in the image objects (sprite or window btw? not sure what exactly is changing here). In that particular object's update method, you would have something checking if the mouse is over it or not, and if it's different than the current state, change to the next state (so refresh bitmap for sprite and refresh for window). This is one method to do it, but there are other methods.

The sprite is changing, what I'm going for is the highlight effect seen in most apps when a button is moused over, how exactly do I check for if the mouse is over?
You compare the mouse's position to the sprite's position.

Code:
// Let's say a is the mouse and b is the sprite

if (a.x >= b.x && a.x <= (b.x + b.width) ) { // check the x condition
    if (a.y >= b.y && a.y <= (b.y + b.height) ) { // check the y condition
        return true;
    }
}
So i got it working visually using the Mouse EX plugin, the only problem is it no longer responds to clicks, Am I doing it wrong?


Code:
Scene_Status.prototype.update = function() {
// Check for if the mouse is hovering the button

if (TouchInput._x >= this._homeButton.x && TouchInput._x <= (this._homeButton.x + this._homeButton.width) ) { // check the x condition
    if (TouchInput._y >= this._homeButton.y && TouchInput._y <= (this._homeButton.y + this._homeButton.height) ) { // check the y condition
        this._homeButton.bitmap = ImageManager.loadPicture('home_hover');
    } else {
    this._homeButton.bitmap = ImageManager.loadPicture('home');
    }
   
};

Heres the full script:

Code:
//-----------------------------------------------------------------------------
// Scene_Status
//
// The scene class of the status screen.

function Scene_Status() {
    this.initialize.apply(this, arguments);
}

Scene_Status.prototype = Object.create(Scene_MenuBase.prototype);
Scene_Status.prototype.constructor = Scene_Status;

Scene_Status.prototype.initialize = function() {
    Scene_MenuBase.prototype.initialize.call(this);
};

Scene_Status.prototype.create = function() {
    Scene_MenuBase.prototype.create.call(this);
    this._statusWindow = new Window_Status();
    this._statusWindow.setHandler('cancel',   this.popScene.bind(this));
    this._statusWindow.setHandler('pagedown', this.nextActor.bind(this));
    this._statusWindow.setHandler('pageup',   this.previousActor.bind(this));
    this._statusWindow.reserveFaceImages();
    this.addWindow(this._statusWindow);
    this.createSpriteButtons();      
};



Scene_Status.prototype.createSpriteButtons = function() {
        this._homeButton = new Sprite_Button();
        this._homeButton.bitmap = ImageManager.loadPicture('home');
        this.addChild(this._homeButton);
        this._homeButton.x = Graphics.width / 2
        this._homeButton.setClickHandler(this.popScene.bind(this));
       
        this._nextButton = new Sprite_Button();
        this._nextButton.bitmap = ImageManager.loadPicture('right');
        this.addChild(this._nextButton);
        this._nextButton.x = Graphics.width / 2 + 100  
        this._nextButton.setClickHandler(this.nextActor.bind(this));  
       
        this._prevButton = new Sprite_Button();
        this._prevButton.bitmap = ImageManager.loadPicture('left');
        this.addChild(this._prevButton);
        this._prevButton.x = Graphics.width / 2 - 100  
        this._prevButton.setClickHandler(this.previousActor.bind(this));  

           
};

Scene_Status.prototype.update = function() {
// Check for if the mouse is hovering the button

if (TouchInput._x >= this._homeButton.x && TouchInput._x <= (this._homeButton.x + this._homeButton.width) ) { // check the x condition
    if (TouchInput._y >= this._homeButton.y && TouchInput._y <= (this._homeButton.y + this._homeButton.height) ) { // check the y condition
        this._homeButton.bitmap = ImageManager.loadPicture('home_hover');
    } else {
    this._homeButton.bitmap = ImageManager.loadPicture('home');
    }
   
};
   
}
Scene_Status.prototype.start = function() {
    Scene_MenuBase.prototype.start.call(this);
    this.refreshActor();
};

Scene_Status.prototype.refreshActor = function() {
    var actor = this.actor();
    this._statusWindow.setActor(actor);
};

Scene_Status.prototype.onActorChange = function() {
    this.refreshActor();
    this._statusWindow.activate();
};
What is it suppose to do when you click it? Simply pop the scene?
I just stole it from the default status scene, it sends you back to the main menu scene. All other buttons within the scene also stopped working, for switching to next and previous actors.
Ohh, it's because you've overwritten the update function. You need to either combine both functions, or alias the old function and call it in the new function (the recommended way, but it doesn't change anything if you're not using other plugins besides the default ones and yours).

To alias the old function and call, do this:

Code:
var alias_sceneStatus_updade = Scene_Status.prototype.update;

// Now in your update function
Scene_Status.prototype.update = function() {
    alias_sceneStatus_update.call(this);
    // the rest of your function here
}

EDIT: So basically what was happening is that your new function didn't execute everything the old function was doing, so it wasn't checking for inputs at all.
Everything is working now, thanks for all the help. 👍
why not just use simple toLocal
Code:
var point = yourSpriteMouse.toLocal(yourDisplayObj);

http://pixijs.download/dev/docs/PIXI.DisplayObject.html#toLocal

edit: oups nothing bad read forget me

Original thread: https://forums.rpgmakerweb.com/threads/mouseover-as-trigger.105019/