Changing over from PIXI v4.0.0 interactivity to PIXI v4.4.1?

Status
Not open for further replies.

Sarlecc

Veteran
Veteran
Joined
Sep 16, 2012
Messages
453
Reaction score
211
First Language
English
Primarily Uses
RMMV
So in one of the plugins I am making I am adding a command window to the map scene. I want it to be inactive until the mouse hovers over and then become inactive again when the mouse leaves. I had this working in version 4.0.0 of PIXI:
Code:
//when mouse goes over command rect this is called by pixi
myWindow_Command.prototype.mouseover = function () {
    this.opacity = 255;
    this.activate();
};

//when mouse leaves command rect this gets called by pixi
myWindow_Command.prototype.mouseout = function () {
    this.opacity = 128;
    this.deactivate();
};

//how it gets added to the map
Scene_Map.prototype.createCommandWindow = function () {
    this._commandWindow = new myWindow_Command(0, 0);
    this.addChild(this._commandWindow);
    this._commandWindow.interactive = true;
    this._commandWindow.deactivate();
}
As of v4.4.1 the above method simply does nothing.
Now I have looked at the new demos for PIXI interactivity, which uses the on (or addListener) function and events like in socket.io. However I have been unsuccessful in getting it to register that the mouse is hovering/leaving the command rect. One of the things I have tried is:
Code:
Scene_Map.prototype.createCommandWindow = function () {
    this._commandWindow = new myWindow_Command(0, 0);
    this.addChild(this._commandWindow);
    this._commandWindow.interactive = true;
    var self = this._commandWindow;
    this._commandWindow.on('mouseover', function() {
        self.opacity = 255;
        self.activate();
        });
    this._commandWindow.deactivate();
}
Now it won't run the event upon mouse over; however I do know the event has been added by calling:
SceneManager._scene._commandWindow._events.mouseover.fn().
So my question is what do I need to change in order for it to work the way how I had it working? Is there a way I could possibly use document.addEventListener instead?
 

LTN Games

Indie Studio
Veteran
Joined
Jun 25, 2015
Messages
704
Reaction score
631
First Language
English
Primarily Uses
RMMV
I use document.addEventListener for my touch events. I've tried using the PIXI interactive but it seems they enable and disable it all the time so I stopped using it due to inconsistency. I currently don't have time to show you how I do it but It's fairly easy to accomplish I'm sure you can figure it out.
All you need is a method which updates the mouse position, and another method which checks if the mouse position is relative to the window you want to touch.
Here is my isButtonTouching for my social media buttons plugin.. Sorry it's in ES6 but the general idea is there.
PHP:
    isButtonTouching () {
      if (!this._mousePos.x || !this._mousePos.y) { return false }
      const x = this.canvasToLocalX(Graphics.pageToCanvasX(this._mousePos.x))
      const y = this.canvasToLocalY(Graphics.pageToCanvasY(this._mousePos.y))
      return x >= 0 && y >= 0 && x < this.width && y < this.height
    }
The mouse position is updated via the event listener.
PHP:
document.addEventListener('mousemove', this.updateMousePos())
All you have to do is change things around a bit. Also, make sure you remove the event listener when you terminate the scene because eventListeners are great for memory leaks lol
 

Sarlecc

Veteran
Veteran
Joined
Sep 16, 2012
Messages
453
Reaction score
211
First Language
English
Primarily Uses
RMMV
Okay thanks LTN I will try that later today after work. :)
Just wish I could use my old method was so simple lol.

Thank you once again @LTN Games I decided on a little bit different approach which I think may avoid the memory leak problems. Here's the code for a more interactive mouse in case anyone is interested for their projects:
Code:
(function (TI) {
    TI._moreEventHandlers = TI._setupEventHandlers;
    TI._setupEventHandlers = function() {
        TI._moreEventHandlers.call(this);
        document.addEventListener('mousemove', this._updateMouseCoors.bind(this));
    };
    
    TI._updateMouseCoors = function (event) {
        this._x = Graphics.pageToCanvasX(event.pageX);
        this._y = Graphics.pageToCanvasY(event.pageY);
    };
    
    
    /**
     * called like so in a windows update method
     * TouchInput.isMouseOver(this, this.myFunction1, this.myFunction2);
     * @param {Object} item
     * @param {function} fn1 this decides what you want to happen when mouse is over the window
     * @param {function} fn2 this decides what you want to happen when mouse is not over the window
     */
    TI.isMouseOver = function (item, fn1, fn2) {
        if (this._x >= item.x && this._x <= item.width + item.x &&
            this._y >= item.y && this._y <= item.height + item.y) {
            if (typeof fn1 === 'function') {
                fn1(item);
            }
        } else {
            if (typeof fn2 === 'function') {
                fn2(item);
            }
        }
    };
    
})(TouchInput);
 
Last edited:

mlogan

Global Moderators
Global Mod
Joined
Mar 18, 2012
Messages
15,354
Reaction score
8,533
First Language
English
Primarily Uses
RMMV

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.

 
Status
Not open for further replies.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

People3_5 and People3_8 added!

so hopefully tomorrow i get to go home from the hospital i've been here for 5 days already and it's driving me mad. I miss my family like crazy but at least I get to use my own toiletries and my own clothes. My mom is coming to visit soon i can't wait to see her cause i miss her the most. :kaojoy:
Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.

Forum statistics

Threads
105,868
Messages
1,017,083
Members
137,583
Latest member
write2dgray
Top