Build a Thumbstick control

TobyToby Member Posts: 478
edited November -1 in Working with GS (Mac)
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?

Comments

  • quantumsheepquantumsheep Member Posts: 8,188
    That's interesting, Toby, thanks for sharing!

    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

  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
  • butterbeanbutterbean Member Posts: 4,315
    We don't yet have multi-touch available right? I just need a D-Pad with 2 buttons for jump and shoot, so when she's walking she can shoot simultaneously
  • ktfrightktfright Member Posts: 964
    Got a question on this: if you just wanted to make it only track its X position, what would I need to do?
  • TobyToby Member Posts: 478
    ktfright, I'd just define the X only and not the Y? Is that what you mean?

    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 :)
  • TobyToby Member Posts: 478
    Well, I don't seem to be able to get this to work, following the wiki word for word. :(

    Resorting to hacked version.
  • ShanestaShanesta Member Posts: 63
    I got this to work, but just copying and pasting the code expression does not work. ( is that supposed to work?) I had to manually recreates it to get it to work. Just copying the working expression and pasting it again causes it to break, there is definitly some wonkyness in the expression editior. I got it controlling my actor as well as the speed of it's movement.

    This works great. Thanks Code Monkey!
  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    Copy and pasting the expression should not work because the attributes must be individually selected from the Attribute Browser/Expression Editor.
  • sewinstonsewinston Member Posts: 51
    So any ideas on how to make this work for multi touch? Everything I've tried has cause the joystick actor to jump to the angle of my other thumb:(
  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    I'm still working on it. So far I've made 2 sets of attributes. And 5 actors always at the position of the 5 touch attributes.
    Still trying to get the kinks out. Getting close.
  • quantumsheepquantumsheep Member Posts: 8,188
    Stay on target... stay on target...

    Dr. Sam Beckett never returned home...
    Twitter: https://twitter.com/Quantum_Sheep
    Web: https://quantumsheep.itch.io

  • ShanestaShanesta Member Posts: 63
    Here is what I was trying, having 2 thumbstick controls in my game, each need to track what ever touch is in that area, I made attributes for LStickX , LStickY, RStickX, RStickY. The thumbstick controls look at these values instead of touches/mouse clicks. I made 1 actor that track the touches, and controls the above values.

    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.
  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    Okay. http://gamesalad.com/game/play/22929

    Finally got it to work. Its pretty stable for any touch no matter which order and even if its the 4th or 5th touch.
  • TobyToby Member Posts: 478
    You're my favourite monkey!
  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    accept no substitution monkeys. :)
  • ktfrightktfright Member Posts: 964
    honestly codemonkey, how do you do it? you basically have the answer to all of the logic here, and i suck at math logic. good job!!! ;)
  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    Stay in school. Don't do drugs.

    This has been a public service announcement brought to you by CodeMonkey.

    :)
  • TobyToby Member Posts: 478
    Have my stick working which is great (Many Thanks CodeMonkey), now I just need to make the actor persistent and remain in the same angle when the stick is released.

    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?
  • TobyToby Member Posts: 478
    Think I figured it out, added a new game attribute called game.angletouch (real)

    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?
  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    If it works it works. I am here just to lay the foundation. :)

    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.
  • TobyToby Member Posts: 478
    Added a firing button and a thrust button to my game scren, now that the thumbstick is working properly but I've hit a problem I'm really stuck on - usually i can figure it out after a while.

    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!
  • TobyToby Member Posts: 478
    Frustrates me that something like this a simple thumb control just gets in the way of the actual 'game making' process. A thumbstick should be a standard feature or pre-built object that you can customise and literally drag and drop into the game environment and target the desired actor.

    At least that way you can just focus on the game creation process.
  • quantumsheepquantumsheep Member Posts: 8,188
    I do happen to agree with Toby on this one.

    Dr. Sam Beckett never returned home...
    Twitter: https://twitter.com/Quantum_Sheep
    Web: https://quantumsheep.itch.io

  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    Yes, it would be nice to have some compound behaviors just like you make your own custom behaviors. Pre-built objects would be nice too. We'll look into it. But for now you can use my example game as a template which I would like to add to the templates list when it becomes more refined and when some more multitouch options become available.
  • TobyToby Member Posts: 478
    Done it!!!!!!

    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?
Sign In or Register to comment.