GameSalad

8 way joystick / 2 way slider control

Hey, just wondering if anyone can explain how to code in a 8 way joystick control or a more simple 2 way left and right control which can slide left and right rather than buttons.

I have had a little search but couldnt find anything and couldnt find templates either, i got hold of one but was too complex to decipher.

Thanks in advance

Comments

  • SocksSocks London, UK.Posts: 12,456

    @brett-norton said:
    a more simple 2 way left and right control which can slide left and right rather than buttons.

    Here's a pretty simple (as simple as I could make it) 2 way slider / control . . . Place an actor at X = 800 and give it a rule that says:

    When touched, constrain X to min(max(mouse X,700),900)

    Now you have an actor that can dragged left and right, but cannot be dragged beyond the x700-x900 pixel range.

    Then in the otherwise section, stick in an interpolate behaviour that says:

    Interpolate X to 800, duration 0.05

    Now you have an actor that can be dragged left and right and will snap back to the middle when released.

  • SocksSocks London, UK.Posts: 12,456
    edited May 9

    Here is a very quick example file . . . (attached)

    Drag the joystick control (white actor) left and right to move the yellow actor.

    The yellow actor uses a very simple rule to determine when to move, if the joystick control's x position is less than 800 then move left, if the joystick control's x position is more than 800 then move right.

    You could of course do lots more with this kind of thing, for example you could measure the distance the joystick control has moved from the default x800 position and use this to control the speed of the yellow actor, so the more you push the joystick control left or right, the faster the yellow actor moves in that direction . . . etc etc.

    [EDIT - now with improved yellow actor !!]

  • brett-nortonbrett-norton Posts: 54

    Sorry socks but what is the exact wording to what you said i cant get it to work did you abbreviate what you said.

    Is it a Constrain Self.positionX ?? or Self.MotionX ??

    This is what i have-

    "in the functions tab"
    Min(700,100) Max(900,100)(Game.mouse.positionX,700),900)

  • SocksSocks London, UK.Posts: 12,456
    edited May 9

    @brett-norton said:
    Is it a Constrain Self.positionX ?? or Self.MotionX ??

    Self position X

    @brett-norton said:
    This is what i have-

    "in the functions tab"
    Min(700,100) Max(900,100)(Game.mouse.positionX,700),900)

    Not sure what the 'functions tab' is ?

    Also I'm not sure what your code is designed to do, my suggestion was:

    min(max(mouse X,700),900)

    . . . . which is very different to . . .

    min(700,100)max(900,100)(mouse X,700),900)

    . . . I suspect that code will produce the number '0' as it doesn't make any sense (when GS can't make sense of an equation it will return 0).

    The min function returns the smaller of the values within the brackets.

    So min(3,6,2,8,7,4) will return 2

    The max function returns the larger of the values within the brackets.

    So max(3,6,2,8,7,4) will return 8

  • IceboxIcebox Posts: 1,244

    @Socks said:
    Drag the joystick control (white actor) left and right to move the yellow actor.

    @Socks Your demo contains one actor only , where is the yellow actor ? :smiley:

  • SocksSocks London, UK.Posts: 12,456
    edited May 10

    @Icebox said:
    @Socks Your demo contains one actor only , where is the yellow actor ? :smiley:

    Whoops ! :)

    Here it is again, this time with the yellow actor !!!

Sign In or Register to comment.