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 Skwiddy

Been playing around with touch input now for my breakout game. I just want to implement something really simple, like: touch on left of screen -> bat moves left (and vice versa).

I have this in my main...
ig.input.bind( ig.KEY.MOUSE1, "CanvasTouch" );

...and in my paddle entity
update: function(){
	     this.parent(); 

	    if( ig.input.state('left') ) {
		this.vel.x = -200;
	    }else if( ig.input.state('right') ) {
		this.vel.x = 200;
	    }else {
		
		if(ig.input.state("CanvasTouch")){
		    if (ig.input.mouse.x < 150){
			this.vel.x = -200;
		    }else if(ig.input.mouse.x >600){
			this.vel.x = 200;
		    }
		}else{
		    this.vel.x = 0
		}
	    }
	 }

This all works fine on the desktop. Both arrow keys and mouse clicks move the paddle, but on a mobile browser touch works really badly (moves once if I click below the game screen towards either far right or far left of the screen).

I thought that mouse input was equivalent to touch input so not sure why it's all going wrong. Any ideas?

1 decade ago by KenD

Is your scaling any different on mobile? Do the hard-coded x values match up with the screen size?

You also might want to try using ig.input.pressed()/released() instead of .state() - I'm using that to allow both clicks and drag gestures on mobile and it works well. Touch events are handled in the same way as mouse up/down/move.
Page 1 of 1
« first « previous next › last »