Anybody know how to go about a Joystick that appears where you touch, such as in agar.io?

I have the joystick made, however i'd like it to appear on the players fingers wherever they touch the screen as long as it's on the left half. This is similar to the popular game agar.io (picture for reference)

Anybody have an idea on how to go about this? I have the joystick made and fully functional, however I'm having problems with making it appear and disappear depending on the players touch and having it function. Thanks!

Comments

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880

    Try this:

    When (All)  
    Mouse button is down  
    Mouse position.x < game.Display Size.Width/2  
        Change Attribute: self position.X To: game.Mouse.Position.X  
        Change Attribute: self position.Y To: game.Mouse.Position.Y  
    Otherwise  
        Change Attribute: self position.X To: -100  
        Change Attribute: self position.Y To: -100  
    
  • ElDaltonElDalton Member Posts: 21

    @RThurman said:
    Try this:

    When (All)  
    Mouse button is down  
    Mouse position.x < game.Display Size.Width/2  
        Change Attribute: self position.X To: game.Mouse.Position.X  
        Change Attribute: self position.Y To: game.Mouse.Position.Y  
    Otherwise  
        Change Attribute: self position.X To: -100  
        Change Attribute: self position.Y To: -100  
    

    Where would I put this code? Inside my joystick?

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880

    That depends on how you have built the joystick. But you might as well try it and see what happens.

    Be sure to test this out on a separate experimental copy of your working game. Just in case it gets messy! Then you don't have to try to fix anything if it turns into a mess. You just go back to your good working copy.

  • NalycanNalycan Member, PRO Posts: 97

    Try this:
    On touch press, spawn joystick actors.
    On touch release, destroy joystick actors.

    If you have 2 (or more) joysticks, just make a rule to spawn joysticks over another actor put in the background. There are so many ways to do this.

    Good luck!

  • ArmellineArmelline Member, PRO Posts: 5,368

    I have a template that does this. I can't link it now but check http://www.armelline.com, in the snippets section.

  • ElDaltonElDalton Member Posts: 21

    @Lycan said:
    Try this:
    On touch press, spawn joystick actors.
    On touch release, destroy joystick actors.

    If you have 2 (or more) joysticks, just make a rule to spawn joysticks over another actor put in the background. There are so many ways to do this.

    Good luck!

    I tried this beforehand, for it seemed like the simplest explanation. However, When the player puts his finger on the screen, the joystick appears right where the players finger is but it doesn't "connect" or "identify" with the players touch to allow it to move around. The player would have to lift their finger up and place it back down (which wouldn't work considering in the final product the joystick will disappear again when the finger is lifted)

  • SocksSocks London, UK.Member Posts: 12,822
    edited December 2015

    @ElDalton said:

    Did you try @RThurman's suggestion ? I think it should work just fine ?

  • ElDaltonElDalton Member Posts: 21

    @Socks said:

    @ElDalton said:

    Did you try @RThurman's suggestion ? I think it should work just fine ?

    Yes I tried, didn't work out too well. My joystick is split into two actors, the background circle that the joystick is contained in and the joystick itself. When trying to do this with both actors it just kinda goes crazy.

  • SocksSocks London, UK.Member Posts: 12,822
    edited December 2015

    //

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880

    @ElDalton said:

    Yes I tried, didn't work out too well. My joystick is split into two actors, the background circle that the joystick is contained in and the joystick itself. When trying to do this with both actors it just kinda goes crazy.

    First, I would suggest that it actually worked. That is, it showed up in the right place just like you asked.

    Now you need to figure out how to make the actual joystick mechanics work based upon a new location. "Crazy" isn't too helpful of a description. You now need to describe how hour joystick is set up and what is causing it to go "crazy" now that it is in a new location. For example, perhaps you have noticed that using the constrain behavior does not work well when the joystick is going to new random locations.

  • ArmellineArmelline Member, PRO Posts: 5,368

    It really sounds like my demo does exactly what you want. Did you try it?

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880

    @Armelline said:
    It really sounds like my demo does exactly what you want. Did you try it?

    @Armelline -- Curiosity is getting the best of me! But I am not able to find your demo. Could you supply a direct link?

  • ArmellineArmelline Member, PRO Posts: 5,368

    Okay, well, yeah, erm, apparently when I last updated the site I removed it by accident...

    My bad!

    http://gshelper.com/shop/gamesalad-templates/armellines-templates/freedom-controller/

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880

    @Armelline -- great demo!

  • Braydon_SFXBraydon_SFX Member, Sous Chef, Bowlboy Sidekick Posts: 9,273

    @Armelline said:
    Okay, well, yeah, erm, apparently when I last updated the site I removed it by accident...

    My bad!

    http://gshelper.com/shop/gamesalad-templates/armellines-templates/freedom-controller/

    Great job!

  • ElDaltonElDalton Member Posts: 21

    @Armelline said:
    It really sounds like my demo does exactly what you want. Did you try it?

    Yes I tried to find your demo before but couldn't, but just got it. This is exactly what I need, however there is an invalid path in the code when I play it and I cant figure out what the path is for me to transfer the demo and build it into my game? Its the first path in both the player and the indicator.

  • ArmellineArmelline Member, PRO Posts: 5,368

    The only attributes used are game.Touch X and game.Touch Y so it's probably those. You'll need to reference the original demo to see where to replace each one.

  • ElDaltonElDalton Member Posts: 21

    @Armelline said:
    The only attributes used are game.Touch X and game.Touch Y so it's probably those. You'll need to reference the original demo to see where to replace each one.

    @Armelline said:
    The only attributes used are game.Touch X and game.Touch Y so it's probably those. You'll need to reference the original demo to see where to replace each one.

    Whats variable that is the if for both actors? That's the variable that is coming up as invalid

  • ArmellineArmelline Member, PRO Posts: 5,368

    game.Touch X and game.Touch Y

Sign In or Register to comment.