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 caxieyou

Hi there
I'm trying to switch from website from mobile device of my little game.

It works fine with the keyboard.

ig.input.bind(ig.KEY.LEFT_ARROW, 'left');

then I use the following code:

if (ig.input.state('left') && this.pos.x > 0) {
this.vel.x = -this.speed;
if (this.standing) {
this.currentAnim = this.anims.runleft;
} else {
this.currentAnim = this.anims.faceleft;
}
this.facing = "left";
}


Instead I tried to use a button, which is just a png file in the corner of the canvas.

ig.input.bind( ig.KEY.MOUSE1, 'leftclick' );

if (ig.input.state('leftclick')
&& ig.input.mouse.x >= 170 // button position
&& ig.input.mouse.x < 190
&& ig.input.mouse.y >= 105
&& ig.input.mouse.y < 125
&& this.pos.x > 0)
{
this.vel.x = -this.speed;
if (this.standing) {
this.currentAnim = this.anims.runleft;
} else {
this.currentAnim = this.anims.faceleft;
}
this.facing = "left";
}


same code here, but when I use the mouse click, it only detect once, which means the character didn't move at all, it just switch to the left.

I wish it could tell if I leave the mouse, so the character could actually move.

How to do this?

Thanks

1 decade ago by caxieyou

Nobody knows?

1 decade ago by monkeyArms

I don't see anything wrong, which probably means the error is being caused by code not included in your post. Do you get any errors in the console?

Also, you may receive more help if you format the code in your post by wrapping it in ## (click on the "show formatting help" link for help)
Page 1 of 1
« first « previous next › last »