Comments (8)
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.
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.
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.
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.
perfect !!!! :)
from melonjs.
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.
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.
so here it is :
https://github.com/obiot/melonJS/issues/6
from melonjs.
Related Issues (20)
- Fix code scanning alert - Polynomial regular expression used on uncontrolled data
- Optimize the `arcTo` function to use `gl.LINES` HOT 1
- Cache or optimize triangulation data used for drawing with fill operation
- `textImage2D` does not accept OffscreenCanvas anymore as a pixel source for texture
- optimize matrix operations using Strassen algorithm ? HOT 5
- compressed textures in WebGL HOT 3
- WebGPU renderer
- TypeScript defenition for loader.preload incorrect HOT 6
- [Feature request] More realistic progress based on bytes for loader and preloader
- Texture is never removed from TextureCache
- TextureCache.length can't be decreased HOT 5
- support using SVG path data when creating a Path2D path HOT 1
- this.body is pointing to Dom type when using Typescript Boilerplate HOT 8
- Animation created from atlas: misaligned hitbox HOT 1
- Some of the Github pages examples are broken HOT 3
- Difficulties with UITextButton HOT 6
- Animation broken on WebGL if TextureAtlas has multiple textures HOT 9
- The result of the flip object vibrates
- Hyperlinks to source code within documentation contain absolute path on obiot's PC HOT 4
- withCredentials does not get set in fetch calls HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from melonjs.