Simple click event on ScreenObject

254 views
Skip to first unread message

kevin.br...@gmail.com

unread,
Feb 24, 2014, 10:08:17 AM2/24/14
to mel...@googlegroups.com
Hi

First i'd like to thank you for your wonderful library :)

Then i have a simple question. There were a lot of changes made on dev 1.0.0 version which i want to use for my project.

Now i'm so confused, that i'm not even able to create a simple click event on a screen object. I load a map from tiled map editor and want to assign a click event, where i want to read the mouse position later.

i tried it in the "onResetEvent" with : me.input.registerPointerEvent("pointerdown", this, "FUNCTION");

but its only executed once when loading the map. Could you help me? :)

Thanks in adanvance
Kev

Aaron McLeod

unread,
Feb 24, 2014, 10:10:56 AM2/24/14
to mel...@googlegroups.com
instead of passing this, try passing me.game.viewport. We made a lot of changes to the screen object to simplify it. We felt it had a bit too many behaviours, and really should just be about the game state changing.


--
You received this message because you are subscribed to the Google Groups "melonJS - A lightweight HTML5 game engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to melonjs+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Aaron McLeod
http://agmprojects.com

kevin.br...@gmail.com

unread,
Feb 24, 2014, 10:24:59 AM2/24/14
to mel...@googlegroups.com
Hi Aaron

Thank you for your fast answer. I'll try this this evening.

So actually i shouldn't load the map in a screenobject? What possibility would you then recommend? also for interactivity like click- or moveevents.

Aaron McLeod

unread,
Feb 24, 2014, 10:30:26 AM2/24/14
to mel...@googlegroups.com
Sorry, loading the map in a screen object is perfectly fine. Passing the screenobject to the input register is not :).

Given you are invoking the registerPointerEvent inside the onResetEvent, and passing this, that means that this is the screen object instance. The method's second parameter expects something of a rectangle object: http://melonjs.github.io/docs/me.input.html#registerPointerEvent. So it needs to have a top bottom, left and right properties defined in order to work. For detecting a click, the viewport should work fine. If you just want to register when someone clicks at any point regardless, you might want to use: http://melonjs.github.io/docs/me.input.html#bindMouse and http://melonjs.github.io/docs/me.input.html#bindTouch instead.

kevin.br...@gmail.com

unread,
Feb 25, 2014, 3:51:37 AM2/25/14
to mel...@googlegroups.com
Hi Aaron

Thank you again for your answers. I don't want to nerve, but firebug tells me, that bindmouse is not a function anymore ("TypeError: me.input.bindMouse is not a function").

Furthermore, i tried to pass the viewport, but nothing happens, not even in firebug:

        me.input.registerPointerEvent("pointerdown", me.game.viewport, function (event) {
            console.log("test");
        });

I use the latest dev-1.0.0 version, compiled by myself.

Greetings

Aaron McLeod

unread,
Feb 25, 2014, 8:29:53 AM2/25/14
to mel...@googlegroups.com
Yes a recent change was refactoring the event handling. So what you want to use is: https://github.com/melonjs/melonJS/blob/1.0.0-dev/src/input/pointer.js#L512. It works in pretty much the same way that bindMouse does. And this will replace the need to use bindTouch as well.

kevin.br...@gmail.com

unread,
Feb 26, 2014, 5:05:26 AM2/26/14
to mel...@googlegroups.com
Interesting fact: In Google Chrome everything (bindPointer, registerPointerEvent pointerdown) works fine. In Firefox both functions are not working.

well, i think i'm gonna use Chrome for dev-version..

Thanks again for your help! :)

melonJS

unread,
Feb 26, 2014, 5:18:43 AM2/26/14
to mel...@googlegroups.com, kevin.br...@gmail.com

Although I tested these last changes using all major browser, I just tested again both the shapes example and the whack-a-mole game and they were both perfectly working under Firefox.

On which machine are you working, and what FF version are you using ?

kevin.br...@gmail.com

unread,
Feb 26, 2014, 5:35:31 AM2/26/14
to mel...@googlegroups.com, kevin.br...@gmail.com
Well, your answer concerning the firefox version made me supicious. So i googled a bit about firefox problems and found a way to "reset" firefox (actually it creates a new profile).

And tadaa..! Suddenly the examples are working and of course the click events I mentioned above is working too. I feel ashamed..

But maybe it helps other users as well :)

Btw, i definitly gonna change to Chrome now.

thanks!

Fabian Meisinger

unread,
Feb 26, 2014, 5:40:22 AM2/26/14
to mel...@googlegroups.com, kevin.br...@gmail.com
Maybe you had an older version of your script files cached?
You should use some addon like web developer tools or firebug and disable the browser cache during development. That helps with a lot of strange problems ;)
Reply all
Reply to author
Forward
0 new messages