jjdv
February 26, 2022, 3:31pm
#1
How to get the code example in JS for the above events?
let touch_x = new RandomSource()
touch_x.getRandomValues()
let mouse = new MouseEvent("e", runtimeScene.)
let distance = Math.sqrt(Math.pow(touch_x,2) + Math.pow(touch_x, 2))
Maybe I got it wrong. I have no idea.
jjdv
February 27, 2022, 9:21am
#2
yes, there is something done from the documations:
read the testing case:
describe('gdjs.RuntimeObject.cursorOnObject', function() {
var runtimeGame = new gdjs.RuntimeGame({
variables: [],
properties: { windowWidth: 800, windowHeight: 600 },
resources: { resources: [] }
});
var runtimeScene = new gdjs.RuntimeScene(runtimeGame);
runtimeScene.loadFromScene({
layers: [{ name: '', visibility: true, effects: [] }],
variables: [],
behaviorsSharedData: [],
objects: [],
instances: [],
});
var object = new gdjs.RuntimeObject(runtimeScene, {
name: 'obj1',
type: '',
behaviors: [],
effects: [],
});
object.setPosition(450, 500);
it('should handle mouse', function() {
runtimeGame.getInputManager().onMouseMove(100, 100);
expect(object.cursorOnObject(runtimeScene)).to.be(false);
runtimeGame.getInputManager().onMouseMove(450, 500);
expect(object.cursorOnObject(runtimeScene)).to.be(true);
});
it('should handle touch', function() {
runtimeGame.getInputManager().onMouseMove(0, 0);
runtimeGame.getInputManager().touchSimulateMouse(false);
runtimeGame.getInputManager().onTouchStart(0, 100, 100);
expect(object.cursorOnObject(runtimeScene)).to.be(false);
runtimeGame.getInputManager().onFrameEnded();
runtimeGame.getInputManager().onTouchStart(1, 450, 500);
expect(object.cursorOnObject(runtimeScene)).to.be(true);
runtimeGame.getInputManager().onFrameEnded();
runtimeGame.getInputManager().onTouchEnd(1);
expect(object.cursorOnObject(runtimeScene)).to.be(true);
runtimeGame.getInputManager().onFrameEnded();
expect(object.cursorOnObject(runtimeScene)).to.be(false);
});
});