Touch Control

Get help using Construct 2

Post » Wed Jul 25, 2012 11:09 am

How do i implement touch control alongside key control ? I already have a keypressed 8direction control set up on my player, but i want it to check if its on a touch device, allowing user to control by touching screen.

I wanted it to move the play to the position the user touches (Like diablo II , click to move).

Obviously id need to have the right animations playing.

Anyways, here my player control with keys ... if anyone could show me an example of how to implement key and touch (using the same controls) then that wud be great :)

note: i did wonder if i cud use transparent buttons that follow player and use the object touched command , but touch plugin doesnt support keyboard usage?

also , i've tried using buttons as the guide states and when testing online (using mouse touch option "yes") it disables my key functions and doesnt do anything.

Anyways heres the CAPX

Download LodoseCapX

Thanks in advance :)
B
4
Posts: 33
Reputation: 391

Post » Wed Jul 25, 2012 2:17 pm

use the "On Touch Start" event then use move sprite position to Touch.X (or Touch.Y) to move your main character sprite to that location
B
41
S
11
G
4
Posts: 428
Reputation: 7,356

Post » Wed Jul 25, 2012 3:38 pm

i've done that but it just instantly moves the play to that location , and does walk there?

i want to make it so you gradually move towards to touch location , the method you supplied instantiates the player at the currently location instantly and without any animation.
B
4
Posts: 33
Reputation: 391

Post » Wed Jul 25, 2012 5:56 pm

if ur player is a bullet then u can change the angle to Touch.X and Touch.Y and increase speed or if it's standard platform behaviour then u can tell it to move in that direction (left or right)
B
10
S
2
G
3
Posts: 18
Reputation: 2,524

Post » Wed Jul 25, 2012 6:29 pm

You can use the same principle I used for the enemy in the other thread by using the bullet behaviour (as PepperedPenguin said). All you need to do is save the touched location in two variables "targetX" and "targetY" on touch, and set the angle of motion towards that position.

If you rename your animations walk0, walk1, etc.. you can use the same formula I used for the enemy frames to handle the animations & directions in just one event. The formula returns 0-7 depending on angle, so you just set the animation to ' "walk"&formula ' and it will pick walk0-walk7 depending on angle.

Check out the animations in Yann's example here.Nimtrix2012-07-25 18:32:54
B
27
S
8
G
8
Posts: 903
Reputation: 8,452

Post » Wed Jul 25, 2012 10:48 pm

Bloody awesome . Nim mate...you've been a diamond today. Thanks everyone!
B
4
Posts: 33
Reputation: 391


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 20 guests