# Touchscreen player control with animation?

**URL:** https://phaser.discourse.group/t/touchscreen-player-control-with-animation/12272
**Category:** Phaser 3
**Created:** [September 4, 2022, 6:57pm UTC](https://phaser.discourse.group/t/touchscreen-player-control-with-animation/12272 "2022-09-04T18:57:21Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![deutandev](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/deutandev/32/6907_2.png) [@deutandev](https://phaser.discourse.group/u/deutandev)
#### Post date: [September 4, 2022, 6:57pm UTC](https://phaser.discourse.group/t/touchscreen-player-control-with-animation/12272/1 "2022-09-04T18:57:21Z")

</div>

Hello, I’m making a mobile game that needs the touchscreen to move the player (swiping right/left). How do I achieve that?  
And how to play animation based on player move direction? I already have ‘idle’, ‘walk\_left’, and ‘walk\_right’ animations.

---

<div class="post-metadata">

### Author: ![Un\_Gamer](https://avatars.discourse-cdn.com/v4/letter/u/a6a055/32.png) [@Un\_Gamer](https://phaser.discourse.group/u/Un_Gamer)
#### Post date: [September 6, 2022, 9:29am UTC](https://phaser.discourse.group/t/touchscreen-player-control-with-animation/12272/2 "2022-09-06T09:29:43Z")

</div>

Not sure what you mean by `swiping right/left`.  
If it is swiping the screen then you can use the below code.

```javascript
this.input.on('pointerup', function (event) {
    var dx = event.upX - event.downX;
    var isMoveLeft = dx > 0 ? false : true;
    if (isMoveLeft) console.log('go left');
    else console.log('go right');
}, this);

```
