Page 1 of 1

Touch Control

PostPosted: Thu Feb 20, 2014 2:48 pm
by Behdadsoft
Hi.

I want Control the Player in xVelocity by click on the screen and move it (-x,+x).
I made it according to Draw Function. but there is a Problem that when I click on the screen, the Player move to click point like adventure games. Now I don't wan't this. I wan't when Click on the screen and move mouse, the Player move only at X coordinate and when release Mouse Button stop the Player at last Position.

first,I made a canvas actor on the screen and added this codes.
Create Actor >> Script Editor:
Code: Select all
draw = 0;


Mouse Button Down (Left) >> Script Editor:
Code: Select all
screen_to_actor (&xmouse, 0);
actor_to_screen (&xmouse, 0);
draw = 1;


Mouse Button Up (Left) >> Script Editor:
Code: Select all
draw = 0;


Draw Actor >> Script Editor:
Code: Select all
if (draw == 1)
{
    MoveTo("Player", 0, 0, 3, "Mouse Position", "");
}

"Mouse Position": Relative to point (xmouse,ymouse). I think one Problem is Related "Mouse Position" because have xmouse and ymouse, While I need only xmouse.

Please Guide Me to Solve this Problem.

Thanks A LOT

Re: Touch Control

PostPosted: Mon Feb 24, 2014 9:06 am
by skydereign
You need to stop the move in your mouse up event. To do so you can do MoveTo("Player", 0, 0, 1, "Player", "").

Re: Touch Control

PostPosted: Mon Feb 24, 2014 5:49 pm
by Behdadsoft
Thanks skydereign. :D
+1

I want my actor only move at x coordinate, while it move at all direction. can you say me how can fix it?

Re: Touch Control

PostPosted: Tue Feb 25, 2014 12:34 pm
by skydereign
Behdadsoft wrote:I want my actor only move at x coordinate, while it move at all direction. can you say me how can fix it?

I'm not entirely sure I understand what you mean. If you only want it to move on the x axis you can just do this.
Code: Select all
MoveTo("Player", view.x+xmouse, Player.y, 3, "Game Center", "");

What this is doing is moving the player to the point to the mouse, without it moving on the y axis. This is done by making the y destination the actor's current y.

Re: Touch Control

PostPosted: Tue Feb 25, 2014 5:22 pm
by Behdadsoft
If you only want it to move on the x axis you can just do this.


Yes, I Only want the Player Move on the x axis. but this code give an error:

wrong number of arguments for MoveTo


What this is doing is moving the player to the point to the mouse, without it moving on the y axis. This is done by making the y destination the actor's current y.


This is a screenshot from My game that I made it for android, but I want control movement with touch:

Re: Touch Control

PostPosted: Tue Feb 25, 2014 5:28 pm
by lcl
The reason for the error was that there was one comma missing from the function call.
Here's the fixed version:
Code: Select all
MoveTo("Player", view.x+xmouse, Player.y, 3, "Game Center", "");

So the comma missing was after the number 3, which is the speed for the actor's movement.

Re: Touch Control

PostPosted: Wed Feb 26, 2014 6:04 pm
by Behdadsoft
ohhh, Thanks lcl. :D

+1