AramCP Posted January 2, 2017 Share Posted January 2, 2017 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 comment Share on other sites More sharing options...
3ddy Posted January 3, 2017 Share Posted January 3, 2017 Try game.input.onDown.add(this.changeStateFunction, this); Link to comment Share on other sites More sharing options...
AramCP Posted January 3, 2017 Author Share Posted January 3, 2017 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 comment Share on other sites More sharing options...
3ddy Posted January 3, 2017 Share Posted January 3, 2017 Just use game.input.onDown and on callback check where was the 'touch', then move the player according to touch position Link to comment Share on other sites More sharing options...
AramCP Posted January 3, 2017 Author Share Posted January 3, 2017 3 minutes ago, 3ddy said: Just use game.input.onDown and on callback check where was the 'touch', then move the player according to touch position Could you show me a little example about how to do it? I usually dont need all that help but im so confused. Link to comment Share on other sites More sharing options...
Cutu Posted January 3, 2017 Share Posted January 3, 2017 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 comment Share on other sites More sharing options...
Recommended Posts