Jump to content

My touch input doesnt work on phones.


Recommended Posts

Hi guys, i implemented touch controls for my game, but they dont work on phones, only in computers with a mouse. Im using this:


//In create function:
game.input.mouse.capture = true;

//And update:
update: function(){
	if(game.input.activePointer.leftButton.isDown){
		game.state.start('game');
	}
},

The only thing that i wanted to do with that is start the game state when you click on the screen, and it works perfectly in my computer, but in my phone does nothing, and it should because in phaser docs it says this:

A Pointer object is used by the Mouse, Touch and MSPoint managers and represents a single finger on the touch screen.

So guys can anyone explain me whi this isnt working? thanks.

Link to post
Share on other sites
7 hours ago, 3ddy said:

Try 


game.input.onDown.add(this.changeStateFunction, this);

 

Maybe that will work for star the game, but for making the player movements, i think it wouldnt, because my player movements look like this right now:

   	if(game.input.activePointer.leftButton.isDown && game.input.activePointer.position.x <= 128){
		player.body.velocity.x = -velocityy;
        player.animations.play('left');
		return;
    	}

	if(game.input.activePointer.leftButton.isDown && game.input.activePointer.position.x >= 128){
		player.body.velocity.x = velocityy;
        player.animations.play('right');
		return;
    	}

    else {
        player.animations.stop();
        player.frame = 3;
    }

As you can see i cant use game.input.onDown.add(this.movementFunction, this);

Pff i dont know how im going to solve this, but thanks anyway.

Link to post
Share on other sites

Hey! I'm learning phaser too and I'm not sure if this is the solution but it might go like this:

game.input.onDown.add((function(e) {
     if(e.position.x <= 128) {
          player.body.velocity = -velocityy;
          player.animations.play('left');
          return;
     } else {
          player.body.velocity.x = velocityy;
          player.animations.play('left');
          return;
     }
}

)); <-- I missed this after the last }, I hope this help you!

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...