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
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