Ravetracer Posted December 29, 2016 Share Posted December 29, 2016 Hi there, currently I'm trying to figure out, how to make on screen controls for mobile devices work. In the HUD I added some GUI objects and tried to trigger key events, when the objects are "hold". Also the buttons are appearing on the screen, but unfortunately they don't work. I'd also tried to use "onClick" event, but it didn't work either. Any ideas? game.HUD.buttonLeft = me.GUI_Object.extend({ init : function (x, y) { var settings = {}; settings.image = 'button_left'; settings.framewidth = 40; settings.frameheight = 40; this._super(me.GUI_Object, "init", [x, y, settings]); this.pos.z = 4; }, onHold : function () { me.input.triggerKeyEvent(me.input.KEY.LEFT, true); return false; } }); game.HUD.buttonRight = me.GUI_Object.extend({ init : function (x, y) { var settings = {}; settings.image = 'button_right'; settings.framewidth = 40; settings.frameheight = 40; this._super(me.GUI_Object, "init", [x, y, settings]); this.pos.z = 4; }, onHold : function () { me.input.triggerKeyEvent(me.input.KEY.RIGHT, true); return false; } }); game.HUD.buttonJump = me.GUI_Object.extend({ init : function (x, y) { var settings = {}; settings.image = 'button_jump'; settings.framewidth = 40; settings.frameheight = 40; this._super(me.GUI_Object, "init", [x, y, settings]); this.pos.z = 4; }, onHold : function () { me.input.triggerKeyEvent(me.input.KEY.UP, true); return false; } }); Quote Link to comment Share on other sites More sharing options...
Parasyte Posted January 2, 2017 Share Posted January 2, 2017 Hi, To use this callback, you have to set the isHoldable property to true. That should fix the issue with the callback not firing. But I've never used it, so I don't really know what to expect. From the source code, it looks like the callback fires once and only once. And the timer value controls how long the button must be held before the callback fires. If you want a callback to trigger every frame, you need to override the `update` method. You can use the various properties that keep track of click state: https://github.com/melonjs/melonJS/blob/4.0.0/src/renderable/GUI.js#L96-L97 That said however, it's probably better if you use the `onClick` and `onRelease` callbacks with `me.input.triggerKeyEvent`; the second param indicates whether the key event is a click (true) or a release (false), and that maps nicely to the GUI_Object click and release callbacks. Quote Link to comment Share on other sites More sharing options...
obiot Posted January 11, 2017 Share Posted January 11, 2017 @Ravetracer just curious, did you make any progress with this ? Quote Link to comment Share on other sites More sharing options...
obiot Posted January 11, 2017 Share Posted January 11, 2017 else there are a few "virtual joystick" out there, that probably worth checking : https://github.com/jeromeetienne/virtualjoystick.js https://github.com/austinhallock/html5-virtual-game-controller .. and other (google returns a long list) I always wanted to look at how to turn one of those as a plugin for melonJS, but it's behind a long list of other things to do Quote Link to comment Share on other sites More sharing options...
Ravetracer Posted January 16, 2017 Author Share Posted January 16, 2017 On 11.1.2017 at 11:49 AM, obiot said: @Ravetracer just curious, did you make any progress with this ? Unfortunately I hadn't the time to try it. You know, XMas, New Years Eve and then work again ;-). But I'll try next days or so when everything calmed down a bit. On 11.1.2017 at 11:53 AM, obiot said: else there are a few "virtual joystick" out there, that probably worth checking : https://github.com/jeromeetienne/virtualjoystick.js https://github.com/austinhallock/html5-virtual-game-controller .. and other (google returns a long list) I always wanted to look at how to turn one of those as a plugin for melonJS, but it's behind a long list of other things to do Yes, looks interesting. Maybe I should try one of these "virtual devices" so prevent to inventing the wheel again ;). Thank you, guys! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.