Build a Thumbstick control
Toby
Member Posts: 478
Hi everyone, I've looked through the forums to no avail, anyone made a reliable Thumbstick control?
I have built a crude one,
- Basically two circle actors one on top of the other, with game (integer) attributes XY defined for each
- Created a game boolean attribute called 'snapto'
- Top actor constrains its XY to the bottom XY
- Rule - On rollover & mouse button down 'snapto' is true (1) constrains the top circle actor to the mouse XY
- Rule - On mouse rolloff from the lower actor's edge & mouse button down, change 'snapto' to false (0)
- Top actor circle snaps back to centre of bottom actors XY
Works ok, needs a little work...
Is there something in the Wiki or a generic one that works perfectly?
I have built a crude one,
- Basically two circle actors one on top of the other, with game (integer) attributes XY defined for each
- Created a game boolean attribute called 'snapto'
- Top actor constrains its XY to the bottom XY
- Rule - On rollover & mouse button down 'snapto' is true (1) constrains the top circle actor to the mouse XY
- Rule - On mouse rolloff from the lower actor's edge & mouse button down, change 'snapto' to false (0)
- Top actor circle snaps back to centre of bottom actors XY
Works ok, needs a little work...
Is there something in the Wiki or a generic one that works perfectly?
Comments
I'll take a look at it once my initial games are out the door!
Cheers again!
QS
Dr. Sam Beckett never returned home...
Twitter: https://twitter.com/Quantum_Sheep
Web: https://quantumsheep.itch.io
http://gamesalad.com/wiki/how_to_gsc_controls
Nice work CodeMonkey thanks heaps and much better than my attempt, will give it a go and apply this. - maybe you should change your name to CodeMonkeyMachine
Resorting to hacked version.
This works great. Thanks Code Monkey!
Still trying to get the kinks out. Getting close.
Dr. Sam Beckett never returned home...
Twitter: https://twitter.com/Quantum_Sheep
Web: https://quantumsheep.itch.io
When All
if game.Touches.touch 1.X is < than 100
if game.Touches.touch 1.Y is < than 100
Constrain Attribute LStickX to Touch 1.X
Constrain Attribute LStickY to Touch 1.Y
When All
if game.Touches.touch 1.X is > than 380
if game.Touches.touch 1.Y is < than 100
Constrain Attribute RStickX to Touch 1.X
Constrain Attribute RStickY to Touch 1.Y
Do this for all 5 touches.
This kind of works, but seems there are still some kinks.
For now I just hard coded the left stick to touch 1, and the right stick to touch 2, this works fine, you just have to touch the left one first. I hope they have a way to dynamically tell which touch instigates the touch event, and allow you to use it. It needs a local touch option to chose from in there with the other touches.
Finally got it to work. Its pretty stable for any touch no matter which order and even if its the 4th or 5th touch.
This has been a public service announcement brought to you by CodeMonkey.
Currently it just snaps to 0, 0
I've tried adjusting the on release - snapto to revert to the ship's last angle with no luck.
I imagine there is an easier way?
Suggestions?
Constrained game.angletouch to vectorToAngle( self.Position.X - game.BaseX2 , self.Position.Y - game.BaseY2 ) inside the Touch1 object
Then constrained attribute self.rotation to game.angletouch inside the player actor.
Seems to work as desired.
Any issues doing it this way Codemonkey?
The only issue I see is if you happen to have your thumb outside of the base circle but still controlling the thumbstick.
If you are using the template/example I posted, you can just move the Constrain Attribute for game.Angle2 in the red circle actor, only when the thumbstick is controlled. It should then keep the last angle while it was controlled.
Having an issue where whenever a game.attribute (shoot or thrust) is called the ship snaps to pointing left rather than using the current rotation angle of the ship to emit particles or spawn bullets.
sooo frustrating, I've tried all kinds of combinations to constrain to the ship angle when these buttons are pressed and nothing seems seems to be working. How is it ignoring the command to constrain and just shoot/thrust left?
Weird thing is if I set fire or thrust to mouse position > inside (not touch) it works exactly how I want. As soon as I change this to on touch it does the stupid left snap thing......... nothiing is telling it to go left which is weird.
HELP - agrhhhhhhhh!
At least that way you can just focus on the game creation process.
Dr. Sam Beckett never returned home...
Twitter: https://twitter.com/Quantum_Sheep
Web: https://quantumsheep.itch.io
It was a missing comma would you believe that caused all the headaches and grief. Literally pulled the whole game apart and testing each bit. Yay! Finally....... spent 2 evenings on this problem.
Thanks for the assistance everyone who commented.
Had a thought, how about a syntax checker on the expression window?