1 decade ago by cosmostail
Hi all,
It is a simple issue but I have spent hours and hours without make progress.. can someone help?
The issue was , "I need a way to detect whether an entity is clicked/touched".. I have made it works under impactJs by using the following code. The same code also works under AppMobi emulator... But once I pushed to the cloud and tested on iphone, it doesn't work anymore...
ig.input.bind( ig.KEY.MOUSE1, 'my_click');
update: function(){
if (ig.input.pressed('my_click') && this.inFocus()) {
//console.log('clicked');
this.kill();
}
},
inFocus: function() {
return (
(this.pos.x <= (ig.input.mouse.x + ig.game.screen.x)) &&
((ig.input.mouse.x + ig.game.screen.x) <= this.pos.x + this.size.x) &&
(this.pos.y <= (ig.input.mouse.y + ig.game.screen.y)) &&
((ig.input.mouse.y + ig.game.screen.y) <= this.pos.y + this.size.y)
);
},
First I thought it might be to do with directCanvas, so I did the following test, added a
<div id="Shootbutn" ontouchstart="handleInput('myTouch');" ontouchend="handleInput('myTouch');"></div>
and bind it in index.html as follow
AppMobi.canvas.execute('ig.input.actions[\'my_click\']=true;ig.input.presses[\'my_click\']=true;');
I'm pretty sure the touch event is fired because once I remove the this.inFocus() in updates, it did kill all my entities... but it seems the touch doesn't react right away or sometime requires few more touches...
At this moment, I'm really confused how the things work between impactJs and AppMobi...
It is a simple issue but I have spent hours and hours without make progress.. can someone help?
The issue was , "I need a way to detect whether an entity is clicked/touched".. I have made it works under impactJs by using the following code. The same code also works under AppMobi emulator... But once I pushed to the cloud and tested on iphone, it doesn't work anymore...
In main.js, I bind the Mouse1 event
ig.input.bind( ig.KEY.MOUSE1, 'my_click');
In my entity js, I have added the following code in update
update: function(){
if (ig.input.pressed('my_click') && this.inFocus()) {
//console.log('clicked');
this.kill();
}
},
inFocus: function() {
return (
(this.pos.x <= (ig.input.mouse.x + ig.game.screen.x)) &&
((ig.input.mouse.x + ig.game.screen.x) <= this.pos.x + this.size.x) &&
(this.pos.y <= (ig.input.mouse.y + ig.game.screen.y)) &&
((ig.input.mouse.y + ig.game.screen.y) <= this.pos.y + this.size.y)
);
},
First I thought it might be to do with directCanvas, so I did the following test, added a
<div id="Shootbutn" ontouchstart="handleInput('myTouch');" ontouchend="handleInput('myTouch');"></div>
and bind it in index.html as follow
AppMobi.canvas.execute('ig.input.actions[\'my_click\']=true;ig.input.presses[\'my_click\']=true;');
I'm pretty sure the touch event is fired because once I remove the this.inFocus() in updates, it did kill all my entities... but it seems the touch doesn't react right away or sometime requires few more touches...
At this moment, I'm really confused how the things work between impactJs and AppMobi...