Comments (5)
UI libraries are not affected anyhow by PlayCanvas, except the fact that mouse input will propagate.
That means if your game does not care about events on canvas itself, then it just uses UI events as it used to.
But if you do care about custom input to canvas as well as UI above it, and you have a mixture of different behaviours, like in here for example: http://apps.playcanvas.com/max/tanky/colorTanks
Where you want mouse to be working in game when you still hovering minimap. And UI buttons still work.
That means it is up to a developer to define the logic of mouse interactions, and go from there.
In order to make all (dynamic selector) buttons in bootstrap to ignore mouse events, which is "logic" and not "workaround":
$('body').on('mousedown mousemove mouseup', '.btn', function(evt) {
evt.stopPropagation();
});
It is up to your UI logic to do things, if you want to draw DOM image on top of canvas, or use div with text on top of 3D object using DOM, you might want to still have mouse events working as expected on canvas, ignoring div element above.
Or you might have custom behaviour by adding events as described above.
It is hard to find generic use case for such things as Keyboard and Mouse inputs in order to prevent most issues related to JS fragmentation on different platforms as well as allowing developers to define behaviour the way they want.
If we would provide UI framework, those things would be a part of API it self, but unfortunately we don't have any UI framework atm.
from engine.
The reason why mouse events are handled on Window: we need to handle scenarios when mouse leaves canvas bounds (for example when mouse is down and leaves canvas element), and to have mouse movement when there are elements above canvas and below mouse if developer wants it. Previously there was no option for such.
This gives possibility to have UI elements on top of canvas that have only visual purpose and it is up to developer to stop propagation of mouse events on hovering if dev wants so, or leave as it is.
In order to stop propagation you can easily follow this flow:
uiElement.addEventListener('mousedown', function(evt) {
evt.stopPropagation();
});
Here is example where moving mouse above UI does not breaks game, especially notice it at bottom logo - game still playable.
This change were made to let developer have both options.
from engine.
The fix makes sense, but there are still a few issues. Most UI I imagine will likely be done in jQuery and other libraries (we are using bootstrap for some elements). It makes it a little bit difficult to have normal UI libraries work correctly.
The workaround on my end is to do something like this:
$('body > *:not(canvas)').on("mousedown mouseup mousemove mousewheel DOMMouseScroll", function(event) {
event.stopPropagation();
});
This relies on the canvas always being a direct child of body - is that a valid assumption? Otherwise I'll have to likely make some kind of base css class that all UI elements include.
from engine.
That makes sense. I guess the only other way something like this could work is if UI developers had to manually send the mouse event to the canvas if they wanted pass-through instead of having the developer turn off propagation. It feels like more UI is likely to not want the event to propagate (especially because it will not propagate to the canvas by default in this way), but that is really just my opinion.
I would only recommend adding this to the documentation somewhere because it feels like other devs will probably run into this issue if they are building the UI in HTML.
from engine.
It is a valid point. Developer will have to know the way of achieving "transparent/non-transparent" elements in any case, so knowledge of stopPropagation or some other potential functionality to enforce propagation is necessary (unfortunately only "hacky" solutions come to my head for thing like that).
We will add to API reference for Mouse Input, stating clearly that Mouse events will fire as far as mouse position is within canvas bounds regardless of elements overlapping, unless the overlapped element caches the events and stops its propagation.
from engine.
Related Issues (20)
- Draco throws HOT 1
- Invalid Anim curves counting
- 1.69.0 Install error - Node 16.0 HOT 10
- Implement material level uniform buffer (WebGPU initially) HOT 3
- Invalid base value of anim target
- Handle device lost on WebGPU
- Standalone engine extras import failed
- Changing opacity of transparent material forces shader recompilation HOT 6
- WebXR direct hand input HOT 2
- Docs: update normals in mesh example
- Anim Blend Tree takes incorrect name HOT 1
- Some WebXR examples throw error when refreshed HOT 2
- Add support for the XR emulator HOT 2
- Mesh collider no longer scales in real time HOT 1
- Weighted Blended Order Independent Transparency HOT 1
- Anim Blend Tree accessor override
- Anim Blend Tree 1D weights issue
- Debug bundled ESM engine build fails to build with Vite HOT 2
- Source map shows incorrect scope HOT 5
- Copy-Paste folder HOT 1
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 engine.