update
This commit is contained in:
6
call_js/README.md
Normal file
6
call_js/README.md
Normal file
@ -0,0 +1,6 @@
|
||||
Shows how to call js after clicking on a `Cube` object.
|
||||
|
||||
- Requires html5 target and physics enabled.
|
||||
- Check devtools for output.
|
||||
|
||||
https://github.com/leenkx3d/leenkx/wiki/js
|
||||
33
call_js/Sources/lnx/CallJS.hx
Normal file
33
call_js/Sources/lnx/CallJS.hx
Normal file
@ -0,0 +1,33 @@
|
||||
package lnx;
|
||||
|
||||
import leenkx.trait.physics.PhysicsWorld;
|
||||
import iron.system.Input;
|
||||
|
||||
// This example shows how to call JavaScript after clicking on a Cube object
|
||||
// Requires physics enabled and browser target
|
||||
|
||||
class CallJS extends iron.Trait {
|
||||
|
||||
public function new() {
|
||||
super();
|
||||
var mouse = Input.getMouse();
|
||||
notifyOnUpdate(function() {
|
||||
|
||||
// Check mouse button
|
||||
if (!mouse.started()) return;
|
||||
|
||||
// Pick object at mouse coords
|
||||
var rb = PhysicsWorld.active.pickClosest(mouse.x, mouse.y);
|
||||
|
||||
// Check if picked object is our Cube
|
||||
if (rb != null && rb.object.name == 'Cube') {
|
||||
// Raw JS calls
|
||||
js.Syntax.code('console.log("Cube clicked");');
|
||||
js.Syntax.code('document.title = "Cube clicked";');
|
||||
js.Syntax.code('window.alert("Cube clicked");');
|
||||
} else {
|
||||
js.Syntax.code('console.log("click");');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
BIN
call_js/call_js.blend
Normal file
BIN
call_js/call_js.blend
Normal file
Binary file not shown.
Reference in New Issue
Block a user