I need some help making these touch controls. any ideas?
aspiringgamemaker
Member Posts: 20
in Tech Support
Hey Gamesalad users, I have looked and looked but haven't been able to find how to do this. there are tutorials for a touch joy stick. but what i am looking for is to be able to move an actor right, left, and up by touching anywhere on the screen and dragging you finger in the direction you want the actor to go. similar to the controls in the game Limbo by Play Dead. I need this specific control type for my game to work. any and all help is very much appreciated.
Comments
You say that you can touch anywhere on the screen to do this so if you are only using one touch this can be pretty simple. Gamesalad can track the x,and y coordinates of a touch. I would make it so that the initial touch changes two attributes to store the initial x and y coordinates of the touch.
Then have a rule that determines if the current x or y coordinate is greater or less than the initial. You may want to determine if it is greater by a certain amount so the game isnt too touchy.
For example
if touch.x is > initial.x+2 then change moveright to true (i would have boolean attributes trigger the movement).
and also after the behavior is given to move the actor also change the initial x and y to the new coordinates so that it can determine further movement.
another rule would be if touch.x is < initial.x-2 then change moveright false and moveleft true
Make sure when the touch is release everything is set back to normal
www.rossmanbrosgames.com
Make an invisible actor. Ad rule if mouse button is down change attribute of actor x and y to mouse x and y (where your finger is). Have your hero actor then move towards that position. One thought always.
Google swipe movement gamesalad. There are many explanations and videos related to this.
[Merged two threads.] Please don't create multiple threads for the same issue.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
I don't think he is talking about swipe movements or movement where the actor moves toward the touch point, but rather something that is more like an invisible joystick that many games are using now and it works very well. Am I right @mathewvirgen ?
www.rossmanbrosgames.com
Well, the invisible joystick would require a True False statement based on if touch is pressed or not, which would then create an origin point where the touch is, and then adjust itself based on where the touch moves after that as long as it isnt released, correct?
@tosanu yes that's how I would do it
www.rossmanbrosgames.com
Thanks everyone, @erockross especially. That is exactly what I am trying to do. I will try that pattern and give an update.
@mathewvirgen I ended up trying this out as I was planning on using it for a future game anyway. I ran into one problem in the method i gave you. The initial.x attribute would not reset the more you moved it left or right. This was because the position of your thumb while moving always stayed at a number greater than the previous x so the rule never reset.
I found the best way to fix this was to use a timer the constantly resets the initial.x point to where your thumb is
here is what I did:
Made an actor covering the whole screen.
Rule when touch is pressed:
Otherwise:
Change Game.MoveRight to False
Change Game.MoveLeft to False
Works perfect for left and right movement. If wanted the same logic could be applied to detect up and down movement.
www.rossmanbrosgames.com
Alright... I tried what you said @ecrockross and I can get it to work. What type of attribute did you use for the initial x?
I meant that I "can't " get it to work.
I think it has something to do with the part when you said,
" I would make it so that the initial touch changes two attributes to store the initial x and y coordinates of the touch."
What is the best way to do that
Okay I tried adding a timer, every 0.2 seconds
Constrain: game.initial x to: game.mouse position x
And it works. So thanks for the help everyone.