Need help with joystick controls

RocketBrainRocketBrain Member, PRO Posts: 269
edited November -1 in Working with GS (Mac)
i'm trying to make a joystick but keep it from sliding all over the screen but its not working. Can somebody tell me whats wrong? been driving me nuts.
------------
change attrib CenterX = Self.Position.x
change attrib CenterY = Self.Position.y
-----------
When Touch = Pressed
Constrain attrib Self.Position.X = min(( self.CenterX +30), max( game.Touches.Touch 1.X ,( self.CenterX -30))))
Constrain attrib Self.Position.Y = min(( self.CenterY +30), max( game.Touches.Touch 1.Y ,( self.CenterY -30))))

but when i hit play the actor doesnt follow the touch, which i thought it should. wheres the error? i've checked the coding repeatedly and cant see it.

Comments

  • PhoticsPhotics Member Posts: 4,172
    Does your game scroll?
  • RocketBrainRocketBrain Member, PRO Posts: 269
    not yet. i'm just practicing atm so its just the one actor and nothing else yet.
  • PhoticsPhotics Member Posts: 4,172
    What's the camera origin?
  • RocketBrainRocketBrain Member, PRO Posts: 269
    0
    0
  • PhoticsPhotics Member Posts: 4,172
    The Camera hasn't moved. That's good. You don't have to offset for touch points.

    ...but why are you using CenterX/Y?

    It's like you want to keep it in a 30 radius circle, but I'm not thinking that's the right way to do it. Is the actor supposed to stay in a circle, or not move more than 30 pixels at one time?

    Also, when not using multi-touch, I use mouse position data.
  • RocketBrainRocketBrain Member, PRO Posts: 269
    mouse position can be interchanged with touch on iOS?

    yeah its suppose to stay within a certain distance from a specific point

    and i'm glad you're replying Photics since i've been referencing your textbook ;) thanks again btw for making that kicass tool
  • RocketBrainRocketBrain Member, PRO Posts: 269
    its your example from p98
  • PhoticsPhotics Member Posts: 4,172
    Oh, you're building a thumbstick?

    You shouldn't use the mouse data then... unless there are no other buttons.

    How is the actor moving. Where does it go when you touch it?
  • PhoticsPhotics Member Posts: 4,172
    I think your formula is different than the one in the textbook...

    Yours...
    min(( self.CenterX +30), max( game.Touches.Touch 1.X ,( self.CenterX -30))))

    Textbook...
    min((self.X-Center+30),max(game.Mouse.Position.X,(self.X-Center-30)))

    You have an extra parenthesis at the end.
  • RocketBrainRocketBrain Member, PRO Posts: 269
    that was it! thanks boss

    atm i'm not using it for anything i'm just learning the technique for future games. but it works now which is cool.
  • tenrdrmertenrdrmer Member, Sous Chef, Senior Sous-Chef Posts: 9,934
    you know there is a joystick demo with it all setup for multitouch detection and everything right?

    ___________________________________________________________________________________
    Project Help from Tenrdrmer Click Here

    GS BubbleBall Template HERE!!
    Stacks Level Selection Template HERE!!
    Expanding Option Menu Template HERE!!
    Tenrdrmer's Menu # 3 HERE!!
    AppSolute Entertainment on Facebook
    AppSolute Entertainment on iTunes
Sign In or Register to comment.