Jump to content

Touch Screen Controls


Recommended Posts

Pretty simple question. I read in another post about splitting the game screen in 2 halves and having leftside move left and right move right. I have only half of this working because the screen doesn't split properly. I can walk right but not left.

I also tried adding a onSwipe() function but keep getting activePointer undefined etc. I'm not sure if some stuff has changed in 1.1.5 for this kind of stuff as the posts I was reading were a bit dated.

If anyone knows a way to do a simple left walk, right walk and jump with touch screen I'd be happy to see it.

I do know that phaser creates the mouse pointer, pointer 1 (finger 1) and pointer 2 (finger 2) as standard and I read on multi touch.js in examples but that's not what I need.

What I need is the fingers referenced in an area of screen to walk left and right and jump.

Any help I'd be very thankful!

Thanks :)

Link to post
Share on other sites

Over simplified haha. I just need 50% of left screen and 50% of right screen but the 'markers' for the touch onDown to make the player move. At the minute I've put in a button for making the player jump. It won't reference the player body within the button function but I got it working temporarily for testing. I just need the game to know the left of the screen and the right of the screen.

(this.input.x/this.game.width/2) === LEFT;

That's the jist of the other code I seen to use but I can only press the screen and walk right. BUT, in the left right vars they declare:

Var RIGHT=0;

Var LEFT=1;

If I reverse them numbers the player walks only left and not right. Its got me totally confused and the only other thing I though about doing was making 2 rect areas and declaring them as buttons and doing it like that but I know the width stuff could possibly work.

Its a case of either making alpha buttons and creating a D-Pad or making the 2 rect areas. Not sure at the minute lol.

Thanks :)

Link to post
Share on other sites

the Nadion add-on/library has support for touch controls (it's primarily intended for side-scrollers so it supports left/right and 'action' and 'jump' buttons - but it would be trivial to remove the buttons you don't need). take a look at https://github.com/jcd-as/nadion/blob/master/src/controls.js for details. (disclaimer: yes, I wrote Nadion)

Link to post
Share on other sites

the Nadion add-on/library has support for touch controls (it's primarily intended for side-scrollers so it supports left/right and 'action' and 'jump' buttons - but it would be trivial to remove the buttons you don't need). take a look at https://github.com/jcd-as/nadion/blob/master/src/controls.js for details. (disclaimer: yes, I wrote Nadion)

Nice! 

Wish I'd came on and checked the forum before coding because that's basically what i need haha. I got it working eventually by mapping where the pointer will be in relation to the screen for a left and right part of the screen. Told the game world the if the pointer is pressed above a certain X value, that it does the movement for that part. Code:

        if(this.input.pointer1.x < 399 && this.input.pointer1.isDown)            {                player.body.velocity.x = leftWalk;            }        if(this.input.pointer1.x > 400 && this.input.pointer1.isDown)            {                player.body.velocity.x = rightWalk;            }

:)

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...