Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by Eddie

In Impact, we have ig.input.bind to bind keys to a specific action, like the left and right to our walk action, and there's also ig.input.bindTouch which binds HTML objects to a touch, or a touchstart and touchend event. But is there any form of binding that will allow me to bind a mouse click to an HTML element? I ask because I thought a mouse click would also be considered touch, since mouse clickable objects are considered to be touched on iOS or Android browsers, but such is not the case! I have an HTML button I want to bind to an action in the game so that it changes a parameter that can only be changed in the game loop, but I can't figure out how.

Binding the action to a key works, so that pressing the key does the action and touching the button on my iPhone makes it work too, but not click on it with a mouse on a regular browser. I tried using the object ID like how bindTouch does on a regular bind, but that also does not work.

Thoughts?

1 decade ago by PanTom

You just have to call the javascript function in the onclick event of the button like any other javascipt function.

1 decade ago by edit /

Yes PanTom, obviously that would be ideal, but you misunderstand; I can not do that. I have to edit Player variables with that function (it's a button that levels up a skill) and the only way you can edit player variables is in the game loop. So it HAS to be in there. The only way I've been able to think about it then is binding a button to an action. I tried finding a way to find the player object from an outside JavaScript function, but it doesn't allow for modifying the player. I tried:
var player = ig.Game.playerEntity[0],
var player = ig.MyGame.playerEntity[0],
var player =Game.playerEntity[0],

Etc.

None of them work, so I'm pretty convinced I can't use an outside function to modify the player. Therefore my conclusion was it has to be bound to an action just like a key or touch button. Which works... For the key and the touch, but not the button.

1 decade ago by Eddie

OH! Figured it out. I guess you were right all along PanTom, I was just trying to reference the player in the incorrect way. I was able to do it and it all works.

Thanks a bunch mate!

1 decade ago by rampy

Can you share a snippet of what worked for you?

Thanks!
Page 1 of 1
« first « previous next › last »