Making Your Finger a Joystick in Gamesalad?

jblb2424jblb2424 Member Posts: 65
edited October 2012 in Working with GS (Mac)
Hello :)

I have a game where i use a joystick to control a ball around the screen. However, the joystick really gets in the way of the game...so i want to make it so that the screen IS the joystick. What i mean by that if you move your finger upright, down, or any direction on any part of the screen, the ball will do the same. This way the controls for my game will be a ton easier. Does anyone know how i can do this? Thanks! :)

Comments

  • SearleSamaSearleSama Member Posts: 108
    do you want the ball to mimic the finger movement exactly? if thats the case

    all you have to do is

    when your touch count = 1 record the initial location of the touch.
    find the offset of the ball from the touch then constrain the touch to x and y of the ball plus the offset.

    I used this idea for a targeting game Im working on.
  • jblb2424jblb2424 Member Posts: 65
    That sound like exactly what i wanted, thanks! :) Just one question, whats the offset of the ball and how do i find it?
  • SearleSamaSearleSama Member Posts: 108
    you have to subtract the position of your initial finger touch (as in where you place your finger at the start of the movement) by the current position of the ball to get an offset number. you'll have to do that with x and y.

    when touch = 1
    change initialX to touch.1.x
    change initialY to touch.1.y

    change offsetX to initialX - ball.position.x
    change offsetY to intialX - ball.position.y

    constrain ball.position.x to touch.1.x + offsetX
    constrain ball.position.y to touch.1.y + offsetY

    notice the changes have to happen everytime the finger initally is down.

    you can also make it move faster than the finger by multiplying the contrains by 2 or 3 or 4 (i.e. (touch.1.x + offsetX)*4)

    hope that helps
  • jblb2424jblb2424 Member Posts: 65
    Will that code make the ball move in proportion to my finger, if my finger is anywhere on the screen? I don't want the ball to jump to a certain distance away from my finger. If my finger is 50x away from the ball, i want it to stay that distance. If i take my finger off the screen and put it back at 20 from the ball, i want the ball to stay at that proportion, and move at the same direction as my finger on the screen.
  • SearleSamaSearleSama Member Posts: 108
    it shouldnt jump at all if you got the offset number right. I think i messed it up a bit, the constrains should be touch.x - offsetx not +. It works on mine. I can email you the gs file if you want.
  • Slogghah_GamesSlogghah_Games Member Posts: 29
    @jblb2424 i was wondering, if you could made help me make the circular pad where the ball moves around in it? iv been trying to make one for soooo long, no one has been able to help me.. well not one has realy tried.. so i was hoping if you could. thanks!
  • jblb2424jblb2424 Member Posts: 65
    Look at the "Cross Platform Controller Template" In the gamesalad menu. It has one of those :)
Sign In or Register to comment.