Bind mouse event to PIXI Object

Gamefall Team

Nebula Games Leader
Veteran
Joined
Jan 10, 2017
Messages
348
Reaction score
473
First Language
Italian
Primarily Uses
RMMZ
Hello guys, I want to discuss with you today about a problem that I noticed in all the version of pixi.js that are inserted in Rpg Maker MV.
Maybe I make something wrong, but I can't find any way to make it works.

My problem is related to bound a mouse event to a Sprite (or PIXI.Sprite) or another PIXI object (like Graphics, container etc...).
For example:

Code:
var sprite = new Sprite() (or new PIXI.Sprite() )
sprite.texture = PIXI.loader.resources['myResource'].texture
sprite.position.set(0,0)
sprite.interactive = true //This is needed for make the mouse events works;
sprite.on('mousedown', function() {console.log('myEvent') })
this.addChild(sprite)
This is a pretty basic code and as you can see I have bound to "mousedown" event an anonymous function that should pop-up a log inside the console.
However, this event (or all the other in all the forms: "pointerdown" etc...) does not seem to work or trigger anything, but checking the object properties inside console it looks like the events are bound to the related callback.

I have tried to:
• Make the container (Scene) interactive, too.
• Tried to change the prevent event default inside the Graphics._renderer;
• Try to bind the callback directly to a function

Ex sprite.mousedown = function() { console.log('myEvent') }

So, Am I missing something? Have you my same problem or It should be coded in a different way?

Thank you in advance for the help! :kaoluv:
 

Jonforum

Veteran
Veteran
Joined
Mar 28, 2016
Messages
1,623
Reaction score
1,439
First Language
French
Primarily Uses
RMMV
hum.. i never make more test but what about hack the stage?
PHP:
Stage.prototype.initialize = function() {
    PIXI.display.Stage.call(this);

    // The interactive flag causes a memory leak.
    this.interactive = true; //hack with true
};
* and also its work if your change the pointer-event to none for the div elements?
https://developer.mozilla.org/en-US/docs/Web/CSS/pointer-events
related info here from ivan
http://www.html5gamedevs.com/topic/...n-rpg-maker-mv/?do=findComment&comment=213302

take a look to edit the css style of for the current div id="GameCanvas"
Am really noit sure if it the good box, but if thsi can give you good way to find the issue!
PHP:
style="z-index: 1; position: absolute; margin: auto; top: 0px; left: 0px; right: 0px; bottom: 0px; width: 816px; height: 624px; touch-action: none; cursor: inherit;"
upload_2018-5-15_7-20-42.png

i see touch-action none here... humm maybe it a clue ? tell me
 

Poryg

Dark Lord of the Castle of Javascreeps
Veteran
Joined
Mar 23, 2017
Messages
4,125
Reaction score
10,639
First Language
Czech
Primarily Uses
RMMV
I have covered this problem in a youtube video. I don't take any credit for it, because it's not my solution, I only worked it into a video.


There is some trouble with certain canvas elements that need to be removed before you can use interactive. Remove them and interactive will work just fine.
However, I have found an interesting bug. It will allow interactive for map. In order to allow it on scenes though there needs something more to be done.
 

Gamefall Team

Nebula Games Leader
Veteran
Joined
Jan 10, 2017
Messages
348
Reaction score
473
First Language
Italian
Primarily Uses
RMMZ
Thank you so much @Jonforum and @Poryg !
Thanks to you guys I'm finally able to use PIXI.interactive api!

Thanks for the video Poryg, It works like a charm :kaopride:
 

Jonforum

Veteran
Veteran
Joined
Mar 28, 2016
Messages
1,623
Reaction score
1,439
First Language
French
Primarily Uses
RMMV
Thank you so much @Jonforum and @Poryg !
Thanks to you guys I'm finally able to use PIXI.interactive api!

Thanks for the video Poryg, It works like a charm :kaopride:
show your solution, am curious !
Also did you know if the pixi interactive are more fast than basic listener to document?
in my side i use the bound check
PHP:
element._boundsRect.contains(mX,mY);
it also work good for collision check.

PHP:
    function hitCheck(a, b){
        var ab = a._boundsMap._pad
        var bb = b._boundsMap
        return ab.x + ab.width > bb.x && ab.x < bb.x + bb.width && ab.y + ab.height > bb.y && ab.y < bb.y + bb.height;
    };
I wonder if it would be good for me to go to the API İnteractiviter?
 
Last edited:

Gamefall Team

Nebula Games Leader
Veteran
Joined
Jan 10, 2017
Messages
348
Reaction score
473
First Language
Italian
Primarily Uses
RMMZ
I followed the code suggested by Poryg!

Code:
var Gamefall = Gamefall || {};
Gamefall.Test = Gamefall.Test || {};

(function($) {
    $.GraphicsChanges = {
        modeBox: Graphics._createModeBox,
        video: Graphics._updateVideo,
        upperCanvas: Graphics._createUpperCanvas
    }

    Graphics._createModeBox = function() {
        $.GraphicsChanges['modeBox'].call(this)
        this._modeBox.style.pointerEvents = 'none'
    };

    Graphics._updateVideo = function() {
        $.GraphicsChanges['video'].call(this)
        this._video.style.pointerEvents = 'none'
    };

    Graphics._createUpperCanvas = function() {
        $.GraphicsChanges['upperCanvas'].call(this)
        this._upperCanvas.style.pointerEvents = 'none'
    };
}(Gamefall.Test)
 
Last edited:

Jonforum

Veteran
Veteran
Joined
Mar 28, 2016
Messages
1,623
Reaction score
1,439
First Language
French
Primarily Uses
RMMV
I followed the code suggested by Poryg!

Code:
var Gamefall = Gamefall || {};
Gamefall.Test = Gamefall.Test || {};

(function() {
    $.GraphicsChanges = {
        modeBox: Graphics._createModeBox,
        video: Graphics._updateVideo,
        upperCanvas: Graphics._createUpperCanvas
    }

    Graphics._createModeBox = function() {
        $.GraphicsChanges['modeBox'].call(this)
        this._modeBox.style.pointerEvents = 'none'
    };

    Graphics._updateVideo = function() {
        $.GraphicsChanges['video'].call(this)
        this._video.style.pointerEvents = 'none'
    };

    Graphics._createUpperCanvas = function() {
        $.GraphicsChanges['upperCanvas'].call(this)
        this._upperCanvas.style.pointerEvents = 'none'
    };
}(Gamefall.Test)
ok thanks
 

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

Latest Threads

Latest Posts

Latest Profile Posts

How many parameters is 'too many'??
Yay, now back in action Happy Christmas time, coming back!






Back in action to develop the indie game that has been long overdue... Final Fallacy. A game that keeps on giving! The development never ends as the developer thinks to be the smart cookie by coming back and beginning by saying... "Oh bother, this indie game has been long overdue..." How could one resist such? No-one c
So I was playing with filters and this looked interesting...

Versus the normal look...

Kind of gives a very different feel. :LZSexcite:
To whom ever person or persons who re-did the DS/DS+ asset packs for MV (as in, they are all 48x48, and not just x2 the pixel scale) .... THANK-YOU!!!!!!!!! XwwwwX

Forum statistics

Threads
105,849
Messages
1,016,975
Members
137,563
Latest member
cexojow
Top