Jump to content


Photo

[Example] Analog Sticks [Update 18/04/2013]


  • Please log in to reply
27 replies to this topic

#1 King Tetiro

King Tetiro

    King of Orenna

  • GMC Member
  • 2549 posts
  • Version:GM:Studio

Posted 17 March 2012 - 06:05 PM

Because people are constantly going "How do we make analog sticks", I made a quickie example which I will be updating whenever to ensure even the beginners know how to use it.
 

Analog_V10.png


Analog Stick Example V1.0

Analog Stick Example V1.1 (GMS, multi touch compatible)

It's currently in GM8.0 but fortunately you can import this into GMS so cookies all round! Though I'd like to know how it works on Android/iOS please?

How it works. It used the direction and distance from the center of the circle pad to the mouse co-ordinate to calculate the direction in which the movement would face. I haven't shown it yet but that's because it's a work in progress. But everything's there that you can it yourself...

But this is a W.I.P. I will be working on this later tonight to implement a block that moves around the screen to show what I mean

Until tonight/later/whenever I update it next, I hope this will provide an insight into Analog Stick.

Things left to implement

  • Two+ Analog Sticks (Still yet to work with GMS on Android/iOS (So this won't be for a while)
  • Block that moves to show movement by the Analog Stick
  • Better explanation (I hope to work better explanation. My explaining skills aren't the best)
  • Cookies

Happy programming folks and see people? It's not rocket science. Now excuse whilst I go find a rocket to fly...

EDIT: I know this should be in the Examples section, but I see this more appropiate here as there isn't a section for Touchscreen Examples


Edited by King Tetiro, 18 April 2013 - 06:15 PM.

  • 6

If I have provided feedback on a game of yours, it would be epic if you do the same!
LND_Twitter_Icon.png Leon_Topic_Icon.png

Leon [PC]  | |Texture Page Calculator for GMStudio | Analog Sticks for GMStudio


#2 Exe_Mas

Exe_Mas

    GMC Member

  • GMC Member
  • 161 posts

Posted 17 March 2012 - 07:02 PM

Excellent! Very useful!!
I have made mine own system before, and it works great too. This is really cool because is simple to implement on your own games, I will like you to explain a little more, for example, what some variables do, but the example is great!
+1
  • 0

#3 NakedPaulToast

NakedPaulToast

    GM Studio/Mac/Win

  • GMC Member
  • 8808 posts
  • Version:GM:Studio

Posted 17 March 2012 - 07:28 PM

Because people are constantly going "How do we make analog sticks" and I'm the only one who actually worked out how to do it, I guess I have no choice but to be "THAT" guy. You know, "THAT" guy who has to give the example. So I made a quickie example which I will be updating next week to ensure even the beginners know how to use it.

[snip]

Whatever would the GMC do without you.

Now can you do an example of somebody sticking their finger down their throat and gacking?
  • 3

If the Bible truly is inspired by God, you would think that somebody as omnipotent and all-knowing would have known to get his message out using TCP instead of UDP.

 


#4 King Tetiro

King Tetiro

    King of Orenna

  • GMC Member
  • 2549 posts
  • Version:GM:Studio

Posted 17 March 2012 - 07:30 PM

Because people are constantly going "How do we make analog sticks" and I'm the only one who actually worked out how to do it, I guess I have no choice but to be "THAT" guy. You know, "THAT" guy who has to give the example. So I made a quickie example which I will be updating next week to ensure even the beginners know how to use it.

[snip]

Whatever would the GMC do without you.

Now can you do an example of somebody sticking their finger down their throat and gacking?


Well I'm probably not the only person but no-one else is sticking their hand up.

I would do that but we seem to have that corner covered with all those minecraft clones

EDIT: But just for you NakedToast, I'll change the topic background note for you.

Edited by King Tetiro, 17 March 2012 - 07:36 PM.

  • 0

If I have provided feedback on a game of yours, it would be epic if you do the same!
LND_Twitter_Icon.png Leon_Topic_Icon.png

Leon [PC]  | |Texture Page Calculator for GMStudio | Analog Sticks for GMStudio


#5 billyguidry

billyguidry

    GMC Member

  • GMC Member
  • 16 posts
  • Version:GM:Studio

Posted 17 March 2012 - 10:29 PM

This is an example of a virtual joystick in a game i've been working on. It also using swiping. The virtual joystick is created anywhere you touch on the left side of the screen. The swiping is done anywhere on the right.

Joystick example on youtube
  • 0

#6 King Tetiro

King Tetiro

    King of Orenna

  • GMC Member
  • 2549 posts
  • Version:GM:Studio

Posted 17 March 2012 - 10:38 PM

This is an example of a virtual joystick in a game i've been working on. It also using swiping. The virtual joystick is created anywhere you touch on the left side of the screen. The swiping is done anywhere on the right.

Joystick example on youtube


Now that's an expansion I can easily implement in the future examples. If people wish for something like this?
  • 0

If I have provided feedback on a game of yours, it would be epic if you do the same!
LND_Twitter_Icon.png Leon_Topic_Icon.png

Leon [PC]  | |Texture Page Calculator for GMStudio | Analog Sticks for GMStudio


#7 Spector_Slayor

Spector_Slayor

    GMC Member

  • New Member
  • 81 posts

Posted 17 March 2012 - 11:03 PM

This is an example of a virtual joystick in a game i've been working on. It also using swiping. The virtual joystick is created anywhere you touch on the left side of the screen. The swiping is done anywhere on the right.

Joystick example on youtube


Now that's an expansion I can easily implement in the future examples. If people wish for something like this?


Imo that's the way all virtual control sticks should work to make it more comfortable for people with varying finger lengths and how they prefer to hold their phones/tablets. I've already made myself one too, yours looks good billy.
  • 0
Did you know we can rotate objects in the room editor now┐ =)
Sneak Peak at my upcoming game [ScreenShot]
//Don't drink and script you may crash your computer.
Posted Image

#8 billyguidry

billyguidry

    GMC Member

  • GMC Member
  • 16 posts
  • Version:GM:Studio

Posted 17 March 2012 - 11:11 PM

This is an example of a virtual joystick in a game i've been working on. It also using swiping. The virtual joystick is created anywhere you touch on the left side of the screen. The swiping is done anywhere on the right.

Joystick example on youtube


Now that's an expansion I can easily implement in the future examples. If people wish for something like this?



Yes, an expansion would be great. Once GM Studio user see it's full potential, it could be used in most games where applicable. Programming it was real simple. I got the idea from connorcarpenter while i was testing GMHTML5! If you need any help in creating this expansion, I'd gladly help.
  • 0

#9 King Tetiro

King Tetiro

    King of Orenna

  • GMC Member
  • 2549 posts
  • Version:GM:Studio

Posted 18 March 2012 - 08:04 AM

Nope I think I understand the base of this code. Though I would like to see your calculations for how much of the left screen can be used by the analog stick
  • 0

If I have provided feedback on a game of yours, it would be epic if you do the same!
LND_Twitter_Icon.png Leon_Topic_Icon.png

Leon [PC]  | |Texture Page Calculator for GMStudio | Analog Sticks for GMStudio


#10 tomasart

tomasart

    GMC Member

  • GMC Member
  • 269 posts

Posted 18 March 2012 - 10:20 AM

i have answer this post yesterday: http://gmc.yoyogames...howtopic=534305 , i thing is better to use the YoYo_MouseCheckButton and with a few lines of code you will have your virtual joystick with multitouch support. Your example is very good but obsolete for the studio version.
  • 0

#11 nujuat

nujuat

    Alex Tritt Games

  • GMC Member
  • 268 posts
  • Version:GM:Studio

Posted 18 March 2012 - 10:52 AM

I have made my own virtual keys (so it doesn't stay on when you move your finger around the screen). If you want I can show you the code, but I won't bother if nobody wants to see it (it's in the middle of my multitouch drawing code for drawing galaxy, so I would rather not extract it).

EDIT: BTW I would have something like this for a joystick:
my_joystick_touched = 0
for (i=0; i<5; i+=1)
    {
    if my_joystick_touched = 0
        {
        if YoYo_MouseCheckButton(i,mb_left)
            {
            if point_distance(x,y,YoYo_MouseX(i), YoYo_MouseY(i)) < 256
                {
                my_joystick_touched = 1
                my_joystick_direction = point_distance(x,y,YoYo_MouseX(i), YoYo_MouseY(i))
                }
            }
        }
    }
Where "my_joystick_touched" is whether the joystick is down or not and "my_joystick_direction" is the direction it is being pushed.

You should be able to have multiple joysticks with multiple instances of this object. The draw event shouldn't be that hard to do.

Edited by nujuat, 18 March 2012 - 11:09 AM.

  • 0

COGios.png  - - http://alextrittgames.com/  - - DGios.png
iOS - HTML5 - PC - MAC - OUYA


#12 King Tetiro

King Tetiro

    King of Orenna

  • GMC Member
  • 2549 posts
  • Version:GM:Studio

Posted 18 March 2012 - 11:24 AM

Ok, let me clear up a few things

  • This Example is only assuming you want the game to only handle 1 touch at a time. I made that clear in the beginning that once I can get Android/iOS to work and when I have a phone for it, I'd be doing multi touch
  • This is just an example tomasart. It's the way I conquered the problem with just the only problem was restraining the stick to be within the circle pad
  • I am open to the suggestions and in future versions, all these aspects will be done. There WILL be an example with two analog sticks and an example of the YoYo_ functions replacing the mouse_check_button. Did I already mention I have yet to test my game and example or an Android/iOS?
  • This is just one way of doing it. I know there's a ton of other ways. But this way works. And apart from a few others who worked it out, there isn't must to go on in terms of learning how to. I did this engine by scratch Pre-Beta for Legena : The New Dawn. I had no clue what functions where in GMS aside from mouse_buttons and I had no clue about the multi-touch. But it's nice to know that YYG are expanding GMS with multi-touch.

Now as for you nujuat...

Would you mind providing a screenshot of what you are talking about? I see the code works but I can't see what it does and I'm intrigued

Edited by King Tetiro, 18 March 2012 - 11:25 AM.

  • 0

If I have provided feedback on a game of yours, it would be epic if you do the same!
LND_Twitter_Icon.png Leon_Topic_Icon.png

Leon [PC]  | |Texture Page Calculator for GMStudio | Analog Sticks for GMStudio


#13 tomasart

tomasart

    GMC Member

  • GMC Member
  • 269 posts

Posted 18 March 2012 - 12:23 PM

do not be angry, this was not my intention. just say it's a good example for GM8, but for the studio can do in 15 minutes even with two virtual sticks, one to move and another for the shoot direction with the new functions and with only a few lines of code. I thing this forum is for sharing experience, My apologize if I offended you...
  • 0

#14 King Tetiro

King Tetiro

    King of Orenna

  • GMC Member
  • 2549 posts
  • Version:GM:Studio

Posted 18 March 2012 - 12:25 PM

do not be angry, this was not my intention. just say it's a good example for GM8, but for the studio can do in 15 minutes even with two virtual sticks, one to move and another for the shoot direction with the new functions and with only a few lines of code. I thing this forum is for sharing experience, My apologize if I offended you...


Nah I'm not angry, just wanted to make a few things clear :tongue:
No offense taken because you said, it was done in GM8

Besides, I'm too good a mood to be angry at anyone.

I plan on updating this in the future. When I have more time lol
  • 0

If I have provided feedback on a game of yours, it would be epic if you do the same!
LND_Twitter_Icon.png Leon_Topic_Icon.png

Leon [PC]  | |Texture Page Calculator for GMStudio | Analog Sticks for GMStudio


#15 King Tetiro

King Tetiro

    King of Orenna

  • GMC Member
  • 2549 posts
  • Version:GM:Studio

Posted 18 March 2012 - 05:26 PM

King Tetiro, your code is very laggy on my LG Optimus S. The game runs fine, even with dynamic 2D fluids but as soon as I used your pad the game dropped to 5 fps until I let go.

In addition to the other critiques in this thread I think an example update is in order.


Huh that's strange. I haven't used any code that should cause that problem. I will have a look into this

EDIT: I hope you can help me out Robert with the help request I sent you by PM. I have a vague idea what the problem is. I just need some confirmation

Edited by King Tetiro, 18 March 2012 - 05:37 PM.

  • 0

If I have provided feedback on a game of yours, it would be epic if you do the same!
LND_Twitter_Icon.png Leon_Topic_Icon.png

Leon [PC]  | |Texture Page Calculator for GMStudio | Analog Sticks for GMStudio


#16 Flipper2

Flipper2

    GMC Member

  • GMC Member
  • 15 posts
  • Version:GM:Studio

Posted 26 August 2012 - 03:59 PM

I made a multi-touch engine with King Tetiro's engine. Thank you King for the engine!
Analog Stick with multi-touch download here
  • 2

#17 fuegerstef_2

fuegerstef_2

    GMC Member

  • GMC Member
  • 474 posts
  • Version:GM:Studio

Posted 26 August 2012 - 04:32 PM

Any reason there are codeblocks like this in the example:

turn = arctan2(y2 - y1,x2 - x1) * 180 / pi;
turn = turn mod 360;
if (turn < 0)
turn = turn + 360;
return(360 - turn);


if it would be much, much faster executed like this:

return(point_direction(x1,y1,x2,y2,))

Just asking.


EDIT:
And wouldn't a switch statement be better and faster too instead of going through 7 different if statements?


EDIT2:
And wouldn't this:
dir = round(point_direction(x1,y1,x2,y2) / 90);
if (dir = 0) {dir = 4};

be faster and better than what King did:
turn = arctan2(y2 - y1,x2 - x1) * 180 / pi;
turn = turn mod 360;
    if (turn < 0)
        turn = turn + 360;


----
cr = round(turn / 90);
if (cr == 0 || cr == 4)
   d = 4;
else if (cr == 1)
   d = 3;
else if (cr == 2)
   d = 2;
else
d = 1;


EDIT3:
And couldn't the rest of the code (from script structure to drawing and setting it up with vars) be much easier for others to understand, easier to implement and faster executed too if someone did it who actually codes better than he brags?

Edited by fuegerstef, 26 August 2012 - 05:02 PM.

  • 0

#18 King Tetiro

King Tetiro

    King of Orenna

  • GMC Member
  • 2549 posts
  • Version:GM:Studio

Posted 27 August 2012 - 07:16 AM

Any reason there are codeblocks like this in the example:

turn = arctan2(y2 - y1,x2 - x1) * 180 / pi;
turn = turn mod 360;
if (turn < 0)
turn = turn + 360;
return(360 - turn);


if it would be much, much faster executed like this:

return(point_direction(x1,y1,x2,y2,))

Just asking.


EDIT:
And wouldn't a switch statement be better and faster too instead of going through 7 different if statements?


EDIT2:
And wouldn't this:
dir = round(point_direction(x1,y1,x2,y2) / 90);
if (dir = 0) {dir = 4};

be faster and better than what King did:
turn = arctan2(y2 - y1,x2 - x1) * 180 / pi;
turn = turn mod 360;
    if (turn < 0)
        turn = turn + 360;


----
cr = round(turn / 90);
if (cr == 0 || cr == 4)
   d = 4;
else if (cr == 1)
   d = 3;
else if (cr == 2)
   d = 2;
else
d = 1;


EDIT3:
And couldn't the rest of the code (from script structure to drawing and setting it up with vars) be much easier for others to understand, easier to implement and faster executed too if someone did it who actually codes better than he brags?


It's not meant to be a perfect code for the angle calculation engine. It was just meant to give you an idea. Of course I haven't updated the engine in months. In fact, I only stumbled on the topic again today. I'll see what I can do!
  • 0

If I have provided feedback on a game of yours, it would be epic if you do the same!
LND_Twitter_Icon.png Leon_Topic_Icon.png

Leon [PC]  | |Texture Page Calculator for GMStudio | Analog Sticks for GMStudio


#19 Chocolateau

Chocolateau

    GMC Member

  • New Member
  • 2 posts
  • Version:GM:Studio

Posted 12 January 2013 - 04:05 PM

Hi guys i've downloaded this example and i've imported it into my project

how do i add the controller to the UI? and then attach it to the player character as the controller?

i'd appreciate the help. thanks :)
  • 0

#20 King Tetiro

King Tetiro

    King of Orenna

  • GMC Member
  • 2549 posts
  • Version:GM:Studio

Posted 15 April 2013 - 09:41 PM

Well guys, I'll be providing a new version of the example. One that supports multi touch. Because with my new project in the works, I was able to work out how to do it.

 

So expect an update very soon! One with multi touch :D


  • 0

If I have provided feedback on a game of yours, it would be epic if you do the same!
LND_Twitter_Icon.png Leon_Topic_Icon.png

Leon [PC]  | |Texture Page Calculator for GMStudio | Analog Sticks for GMStudio


#21 King Tetiro

King Tetiro

    King of Orenna

  • GMC Member
  • 2549 posts
  • Version:GM:Studio

Posted 15 April 2013 - 09:47 PM

Sounds awesome man, the community thanks you.

 

Thanks for the thanks! I needed to update it eventually anyway lol At least this time I have GMStudio. I'll be doing some final tests for it tomorrow :D


  • 0

If I have provided feedback on a game of yours, it would be epic if you do the same!
LND_Twitter_Icon.png Leon_Topic_Icon.png

Leon [PC]  | |Texture Page Calculator for GMStudio | Analog Sticks for GMStudio


#22 King Tetiro

King Tetiro

    King of Orenna

  • GMC Member
  • 2549 posts
  • Version:GM:Studio

Posted 18 April 2013 - 06:16 PM

Well guys! I finally got an update for this!

 

Analog Stick Example V1.1 (GMS, multi touch compatible)

 

This new version is made in GMS. But the more important update is it is now GMS compatible and allows for multi touch. A vast improvement over the last version!

 

If you have any suggestions for improving the script, give me a shout!

 

Enjoy!


  • 0

If I have provided feedback on a game of yours, it would be epic if you do the same!
LND_Twitter_Icon.png Leon_Topic_Icon.png

Leon [PC]  | |Texture Page Calculator for GMStudio | Analog Sticks for GMStudio


#23 King Tetiro

King Tetiro

    King of Orenna

  • GMC Member
  • 2549 posts
  • Version:GM:Studio

Posted 24 April 2013 - 01:55 PM

Well I never! Who'd have thought my first example would have got over 500 downloads since I put it up for download? 539 downloads to be exact!

 

I must say I'm very honoured to have so many downloads. As a result, I plan to continue providing support not just for Analog Sticks. I have thought about providing the following

 

  • Scroll Bar
  • Radio Button
  • Checkbox
  • Slider
  • Cursor Trail
  • Drop Down Menu

 

Are there any of these or any others you'd like me to develop support for? If so, give me a shout!


Edited by King Tetiro, 24 April 2013 - 01:57 PM.

  • 0

If I have provided feedback on a game of yours, it would be epic if you do the same!
LND_Twitter_Icon.png Leon_Topic_Icon.png

Leon [PC]  | |Texture Page Calculator for GMStudio | Analog Sticks for GMStudio


#24 AlekM

AlekM

    GMC Member

  • GMC Member
  • 140 posts
  • Version:GM:Studio

Posted 21 August 2013 - 05:40 PM

do the scroll bar, It is very much needed for my achievements room.

 

Also, I've been getting this error with studio version (haven't tried other version (1.0) yet!):

In Script Device_Input_Script at line 39 : function "Angle_Script" expects 5 arguments, 3 provided
In Script Device_Input_Script at line 40 : function "Angle_Script" expects 5 arguments, 3 provided
In Object Testy_Obj_Thing, in Event Step event number 0 at line 30 : function "Device_Input_Script" expects 5 arguments, 2 provided
In Object Testy_Obj_Thing, in Event Draw event number 0 at line 37 : function "Angle_Script" expects 5 arguments, 2 provided
In Object Testy_Obj_Thing, in Event Draw event number 0 at line 51 : function "Angle_Script" expects 5 arguments, 2 provided

If you can fix this (I'm using GameMaker:Studio BETA 1.2) it would be great, thanks!


Edited by AlekM, 21 August 2013 - 05:42 PM.

  • 0

#25 Arusiasotto

Arusiasotto

    GMC Member

  • GMC Member
  • 760 posts
  • Version:GM:Studio

Posted 22 August 2013 - 04:20 AM

Now some of those look really useful. Could you have them as separate projects? Trying to dig out all the code for just one feature can be a true PITA. 


  • 0

 

"It should be noted that no ethically-trained software engineer would ever consent to write a DestroyBaghdad procedure. Basic professional ethics would instead require him to write a DestroyCity procedure, to which Baghdad could be given as a parameter." - Nathaniel Borenstein

 

 

 


#26 King Tetiro

King Tetiro

    King of Orenna

  • GMC Member
  • 2549 posts
  • Version:GM:Studio

Posted 22 August 2013 - 05:15 AM

Now some of those look really useful. Could you have them as separate projects? Trying to dig out all the code for just one feature can be a true PITA. 

 

That's not a bad idea! I will be sure to do that :D


  • 0

If I have provided feedback on a game of yours, it would be epic if you do the same!
LND_Twitter_Icon.png Leon_Topic_Icon.png

Leon [PC]  | |Texture Page Calculator for GMStudio | Analog Sticks for GMStudio


#27 dlongoria

dlongoria

    GMC Member

  • New Member
  • 6 posts
  • Version:GM:Studio

Posted 22 October 2013 - 05:54 AM

Because people are constantly going "How do we make analog sticks", I made a quickie example which I will be updating whenever to ensure even the beginners know how to use it.
 

Analog_V10.png


Analog Stick Example V1.0

Analog Stick Example V1.1 (GMS, multi touch compatible)

It's currently in GM8.0 but fortunately you can import this into GMS so cookies all round! Though I'd like to know how it works on Android/iOS please?

How it works. It used the direction and distance from the center of the circle pad to the mouse co-ordinate to calculate the direction in which the movement would face. I haven't shown it yet but that's because it's a work in progress. But everything's there that you can it yourself...

But this is a W.I.P. I will be working on this later tonight to implement a block that moves around the screen to show what I mean

Until tonight/later/whenever I update it next, I hope this will provide an insight into Analog Stick.

Things left to implement

  • Two+ Analog Sticks (Still yet to work with GMS on Android/iOS (So this won't be for a while)
  • Block that moves to show movement by the Analog Stick
  • Better explanation (I hope to work better explanation. My explaining skills aren't the best)
  • Cookies

Happy programming folks and see people? It's not rocket science. Now excuse whilst I go find a rocket to fly...

EDIT: I know this should be in the Examples section, but I see this more appropiate here as there isn't a section for Touchscreen Examples

 

 

Great example, I'm having trouble attaching this to my character though.  Can you show how to connect the joystick  to virtual keys.  I have a exsisting virtual controler with a dpad that controls a character with multiple objects, and I would like to replace the d-pad with the joystick and keep the buttons. 


  • 0

#28 lolhi

lolhi

    GMC Member

  • New Member
  • 1 posts
  • Version:Unknown

Posted 22 September 2014 - 08:21 AM

I have a problem.
 

In Script Device_Input_Script at line 39 : function "Angle_Script" expects 5 arguments, 3 provided
In Script Device_Input_Script at line 40 : function "Angle_Script" expects 5 arguments, 3 provided
In Object obj_joystick, in Event Step event number 0 at line 30 : function "Device_Input_Script" expects 5 arguments, 2 provided
In Object obj_joystick, in Event Draw event number 0 at line 37 : function "Angle_Script" expects 5 arguments, 2 provided
In Object obj_joystick, in Event Draw event number 0 at line 51 : function "Angle_Script" expects 5 arguments, 2 provided
 

  • 0