Giter Site home page Giter Site logo

MouseClick problem about melonjs HOT 8 CLOSED

melonjs avatar melonjs commented on May 10, 2024
MouseClick problem

from melonjs.

Comments (8)

norb42 avatar norb42 commented on May 10, 2024

finally those test instead of collision don't change anything but I had too much JS error with collision without even be able to reproduce them each time

so I have made some change to manage up and down function (to implement drag & drop) and update the sample4 : http://norb.zxq.net/melonJS/sample4/

But I still don't understand why I have this 10 pixel difference inside the mouse event

If you want to take a look at the modif : https://github.com/norb42/melonJS/commits/master

Version 9.3 on FF

from melonjs.

 avatar commented on May 10, 2024

hmm weird...

what about something missing/wrong in the translateMouseCoords() function when returning the x/y pos inside the canvas ? Looks like some offset missing (distance between the page and the canvas?)... Did you try any other example where your canvas is located on the top left part of the page to see if the problem is there too ?

from melonjs.

 avatar commented on May 10, 2024

I was checking the Safari Developer Library and noticed they are using another method to get the mouse position :
https://developer.apple.com/library/safari/#documentation/AudioVideo/Conceptual/HTML-canvas-guide/AddingMouseandTouchControlstoCanvas/AddingMouseandTouchControlstoCanvas.html

as they using the pagex/pagey properties, I wonder it this one is maybe more accurate,and maybe makes more sense with modern browser.

would you give it a try ?

Actually, even if it does not change anything, I think I will update my code to use that. won't maybe make any real difference for mouse event (despite maybe the current bug), but it will make it a little easier to manage touch event (as less variable are then different)

from melonjs.

 avatar commented on May 10, 2024

http://stackoverflow.com/questions/5085689/tracking-mouse-position-in-canvas

Is your canvas by any chance 10px far from the page border ? seems it's the issue to me ...

And actually it is, based on the below link, i update the translateMouseCoord function like this :

    /* ---

         translate Mouse Coordinates

        ---                             */
    function translateMouseCoords(x, y) {
        var obj = me.video.getScreenCanvas();
        var curleft = 0;
        var curtop = 0;

        do {
            curleft += obj.offsetLeft;
            curtop += obj.offsetTop;
        } while( obj = obj.offsetParent ) 

        return new me.Vector2d(x - curleft,
                               y - curtop);
    };

and also now calls it using pageX,pageY
translateMouseCoords(e.pageX, e.pageY)

and... it works !

from melonjs.

norb42 avatar norb42 commented on May 10, 2024

perfect !!!! :)

from melonjs.

 avatar commented on May 10, 2024

messed up with the commits, but I used the above method as well and "cached" the canvas offset within the page.
I don't know if you plan any pull request, else on my side I plan to finish some first implementation based on yours for this weekend, and maybe will also add touch event (once mouse event are fully done, adding some touch event is quite easy)

from melonjs.

norb42 avatar norb42 commented on May 10, 2024

nothing planed, I'm actually test to make mini game to find out what is missing in MelonJS, but you will also implement the enter and leave event ?

from melonjs.

 avatar commented on May 10, 2024

so here it is :

https://github.com/obiot/melonJS/issues/6

from melonjs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.