Jump to content

Recommended Posts

Hi guys, i'm starting with phaser and i'm reading a couple of tutorials. I create an app with one of these tutorials and I'm using Intel XDK to test on my smartphone.

I'd like to ask you, what I need to use at the script to recognize the touchscreen to walk. On web I can use the keyboard (up down left right) to walk.

If you can link me any tutorial that helps with this, or a link from a question on this forum too, i'll be thanks.

Thank you.

Link to post
Share on other sites

First you need to decide how you want to try and translate your key presses into touch actions, given that the input devices are totally different there is no clear 1-to-1 mapping so you have to choose how you want to implement moving with a touch interface. There are a couple of ways I've seen (I've added examples from free ios games, they're probably also available on Android too):

* Swipe (e.g. Redungeon) -> not sure if there is a Phaser input method that helps with swipe, there probably is but if not, hammerjs is a nice clean mature module for handling this, although its not too difficult to work this out yourself either.

* Touch near edge of screen (e.g. cardinal quest 2) -> Again, fairly easy to make happen e.g. fire tap event, get its position on screen, if it is (for example) on the left side of the screen then walk left. You have to tweak it to decide how big that tap area should be and you have to decide what to do if someone taps top-left corner of screen, do you have diagonal movement? or do they walk left or do they walk up? Or do you keep track of the last touch and move in that direction i.e. tap left -> walk left, tap top-left -> walk left, tap top -> walk up, tap top-left -> walk up (I haven't seen this done and it might well feel awful for the user).

* Touch a tile to walk to (e.g. Quest of Dungeons) -> I've seen this done too, having previously played 'touch near edge' navigation games it feels a little odd but everyone is different. Works well for grid-based games, fairly easy to work out which grid cell has been tapped, but you'd have to do some path-finding to go from current location to desired location which could get tricky, i.e. for a classic roguelike you'd have to have a mechanism to stretch the movement over multiple turns (something like an action queue would do this). Given that you're using keyboard as your primary input currently this method of navigation is pretty different from your current implementation.

For each of these methods you might want to repeat the action if the user holds down the key i.e. touch left and hold then keep moving the PC left.

If you're feeling really ambitious you might want to implement multiple of these input methods and allow some sort of options/settings/config screen that lets users choose which input method they want to use.

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.

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.

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...