How do I create a virtual Dpad?

Just started using Construct 2? Post your questions here

Post » Wed Aug 19, 2015 1:39 am

How do I create a virtual Dpad for something like a tablet?
I know it has to to with the touch object but how do you set it up in code?

the default Dpad only supported 8 directions right?
how would I do something like this and still be able to do things like double tapping
B
14
S
6
G
1
Posts: 150
Reputation: 1,987

Post » Wed Aug 19, 2015 6:16 am

https://www.scirra.com/tutorials/202/to ... put-method

If you're trying to do something like a platformer, you can always set the sprite to something like:
on sprite touched - simulate platform pressing whichever direction - I don't see why that wouldn't work.
B
71
S
41
G
24
Posts: 356
Reputation: 18,464

Post » Wed Aug 19, 2015 7:45 pm

well its a retro arcade space game
however I need to limit the dpad to only take 2 adjacent inputs?
B
14
S
6
G
1
Posts: 150
Reputation: 1,987

Post » Wed Aug 19, 2015 8:32 pm

Ahh, so like: if these buttons are pressed ->disable other buttons sort of thing?
B
71
S
41
G
24
Posts: 356
Reputation: 18,464

Post » Wed Aug 19, 2015 8:36 pm

ya
basicly 4 directions
right, up, left ,down

and it only lets you press 2 of the 4 direction that are next to eachother
rightup upleft, leftdown, downright would be the limit of multiple buttons being pressed
B
14
S
6
G
1
Posts: 150
Reputation: 1,987

Post » Wed Aug 19, 2015 9:25 pm

I'm also relatively new to C2 so that may be a bit out of my depth. I'm going to try and make something (although, with my keyboard) and hopefully we'll get there together.
B
71
S
41
G
24
Posts: 356
Reputation: 18,464

Post » Thu Aug 20, 2015 1:02 am

k thankyou
B
14
S
6
G
1
Posts: 150
Reputation: 1,987

Post » Thu Aug 20, 2015 8:35 am

Update:
So I've managed to get a system working where:

down/right and down/left neglect other inputs - however, I'm having issues making that work for other combinations. (So if there's someone more experienced that can see what I've done wrong here, please let me know!)
I'm not really changing my method between combinations so I'm not sure why I'm running into this issue. I'm sort of stuck but maybe I'm on to something if a few inputs are working correctly?


My method:

I made a global variable called Touchable and set it to 3. (there is a text box I put in the layout to display this)
I made the player a platform with default controls set to "no" (so we can get vector info)
I set gravity to 0 (so the platform doesn't fall and can be pushed at different angles)
When left/right/up/down are pressed subtract 1 from global variable.
On any key released add 1 to global variable.

Then I defined what inputs do (ie, which angle the platform moves toward, depending on whether global variable is 0 and what is pressed when it is 0. See my capx for numbers).

Here's a link to my project folder. Choose "newproject" and not the other capx (which, somehow, was corrupted?)

Also, it's not notated, sorry!

https://www.dropbox.com/sh/o74rl6lz2du6 ... JTUCa?dl=0
B
71
S
41
G
24
Posts: 356
Reputation: 18,464

Post » Thu Aug 20, 2015 5:42 pm

can you save it to a single file?
so I can take a look?
B
14
S
6
G
1
Posts: 150
Reputation: 1,987

Post » Thu Aug 20, 2015 7:53 pm

https://www.dropbox.com/s/ffru0h3v929bo ... .capx?dl=0

EDIT: I think I've realized that this method just wont work for more than 1 or two keys. Once opposites are introduced, (up/down, left/right), they both end up travelling at 0 degrees. I'll spare the boring details about other things I tried doing using the global variable.

I'm thinking that using key codes (for the inputs I'm using) would work best. I don't know how that would translate to a touch interface...

My thinking would be to have duplicate sprites, one set that is pressable and one set that is not. When 2 are pressed the other two can be destroyed and spawn the unpressable ones. When less than two are pressed the unpressable ones can also be destroyed and spawn pressable ones.
B
71
S
41
G
24
Posts: 356
Reputation: 18,464

Next

Return to Beginner's Questions

Who is online

Users browsing this forum: dickylarsonn02 and 1 guest