Jump to content


Photo

[How To] [Studio] A True Analog Stick


  • Please log in to reply
60 replies to this topic

#1 cotycrg

cotycrg

    GMC Member

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

Posted 31 March 2012 - 04:16 AM

Well I noticed a few people were having issues with Analog sticks on a touchscreen. I decided to tackle the issue myself. This is pretty close to the code I use for Scribble Space (it's a little simpler in my game, since I only need to move on the x axis around the room).

Here's the example, first off: http://crossedshadow...ick_Example.zip (you need to extract it to get the .gmz)

Example Screenshot: Posted Image

I hope this helps out some people. It'd be nice to play some games on my Android that have proper analog controls. Well, now there's no excuse for you guys! :thumbsup:

PS. This can be implemented to have up to 5 analog sticks, if you really needed. Because I included multi-touch functions for everything. The thing where it detects if you're still holding your finger down and you're outside the analog dead-zone even works with multiple analog sticks, as well. Just be careful with placement and check the create event to make sure you're putting the sticks where you really want them! This can even be configured a bit to where the analog stick moves with the finger, if moving to far out, to adjust to the player's play-style. I know the UnReal engine tried something with that, awhile back, so it might be fun to play with. Get creative!

Be sure to post any errors or any mistakes in my code or example in this thread.. Or any way to be more efficient!

Edit: Alright, I removed the code from this post. You couldn't copy/paste it anyways because of the way the forum formatted things, it just messed stuff up. I have the link posted above still for you to view. Another reason for me to remove it was because the code is a bit more complicated now in ordering, because I made the analog stick smooth for moving on the x and y axis around the room. I hope you enjoy!
I made it so that the math for the analog stick is now in the draw event, right next to where it actually draws the stick. I did this because it makes it much smoother when moving around the room.

Edited by cotycrg, 11 October 2012 - 04:20 PM.

  • 5

#2 Robert3DG+

Robert3DG+

    VR Games

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

Posted 31 March 2012 - 04:55 AM

Looks interesting. I will look over it later.

Your example at the top is 404'd by the way.
  • 0

#3 cotycrg

cotycrg

    GMC Member

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

Posted 31 March 2012 - 05:01 AM

Your example at the top is 404'd by the way.

Akkk..my bad. Apparently my ftp won't let people download .gmz files..changed it to a .zip. Oh well. Thanks for the heads up!
  • 0

#4 cotycrg

cotycrg

    GMC Member

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

Posted 31 March 2012 - 11:47 AM

A single analog stick can be got by mapping all other controls to virtual keys, and doing calculations to calculate vector from center of analog to mouse position when it's down.
For two analog sticks you will need to use YoYo_MouseX(n) (seemingly?).
I did such control scheme in my HTML5 game tu.blast() (though that wasn't done in GM).

Essentially, yes. I'm already using YoYo_Mouse in this setup, though. So to make another analog, you'd simply have to make a new set of variables and copy/paste the analog code using the new variables.
  • 0

#5 Robert3DG+

Robert3DG+

    VR Games

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

Posted 31 March 2012 - 12:00 PM

Very nice demo. Well written and commented and the demo showed off some nice interactivity. Posted Image

After playing with it for a while I got some lag, and then I realized the bullets never destroyed themselves. I just made them destroy after leaving the room and everything's a-Okay. Posted Image

+1

Edited by Robert3DG+, 31 March 2012 - 12:00 PM.

  • 0

#6 cotycrg

cotycrg

    GMC Member

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

Posted 31 March 2012 - 12:18 PM

Very nice demo. Well written and commented and the demo showed off some nice interactivity. Posted Image

After playing with it for a while I got some lag, and then I realized the bullets never destroyed themselves. I just made them destroy after leaving the room and everything's a-Okay. Posted Image

+1

Aha. Yeah, I didn't think that far into it, as I was making it really only for the analog. ..I actually didn't even plan the bullets or button..but then I got inspired for a SPACEGAEM. So I figured, why not, for including it in the demo. haha
  • 0

#7 SLarouche

SLarouche

    GMC Member

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

Posted 31 March 2012 - 03:30 PM

Well I noticed a few people were having issues with Analog sticks on a touchscreen. I decided to tackle the issue myself, and even use my method in a game as a control option in my game later. Anyways..here's and example and how to do it.


Very, very nice example. Works like a charm on my galaxy nexus!

Thank you very much.

Smon
  • 0

#8 cotycrg

cotycrg

    GMC Member

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

Posted 03 April 2012 - 05:54 PM


Well I noticed a few people were having issues with Analog sticks on a touchscreen. I decided to tackle the issue myself, and even use my method in a game as a control option in my game later. Anyways..here's and example and how to do it.


Very, very nice example. Works like a charm on my galaxy nexus!

Thank you very much.

Smon

I love to help! I'm glad everyone is liking this. I might update it a bit to make it more clear, if anyone wants.
  • 0

#9 EyeCandy

EyeCandy

    GMC Member

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

Posted 04 April 2012 - 12:49 AM

At the risk of making myself look like a complete idiot...how do I open .gmz files with GameMaker Studio? It doesn't seem to recognize the file type. It has been a pretty good while since I last messed with GameMaker, but with Studio in beta and approaching a release date I want to dive in. I currently make apps using another program, but the ability to make games with such ease is just unbeatable on GM. Anyway, some guidance would be great! :)
  • 0

#10 Robert3DG+

Robert3DG+

    VR Games

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

Posted 04 April 2012 - 01:04 AM

Drag the gmz file into the launcher window after you start studio.
  • 1

#11 EyeCandy

EyeCandy

    GMC Member

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

Posted 04 April 2012 - 04:41 PM

Drag the gmz file into the launcher window after you start studio.


Thanks!


I tested the example on my Xoom tablet and I gotta say it runs extremely smooth. This will come in handy to many who need to use analog sticks in there games. Very nice :)
  • 0

#12 jn2002dk

jn2002dk

    GMC Member

  • New Member
  • 58 posts

Posted 04 April 2012 - 05:03 PM

Awesome

This will certainly save me a lot of time

Thank you! :smile:
  • 0

#13 Smarty

Smarty

    GMC Member

  • Retired Staff
  • 7213 posts
  • Version:GM:Studio

Posted 05 April 2012 - 11:13 AM

//checks for holding, even if out of 'bounds' //this is so that if the user starts holding the analog stick and moves their finger out of the bounds, it doesn't ignore the touch, it keeps following until THAT finger is lifted! (works on C++ runner too!)

Some time ago I was working on a comparable interface, but rather the 4-way and 8-way classical joysticks, forcing the visible stick to go into the cardinal and ordinal directions based on the joystick type required. A downside however is that fingers aren't very accurate, and tend to slide further than the joystick can reach. I too solved this by simply keeping the joystick pushed until the finger was lifted (and only following if it came into the detection areas).

But what I really would love to do be able to give off a very short vibration once the stick touches the perimeter, as if it is touched. It would be a short signal to inform the player that moving their finger further away will only increase the distance from the base (degrading his accuracy and reaction speed) as well as give the joystick a more solid feel through subtle force feedback. I understood that there are reservations within YYG to put functions in GM:Studio to buzz the phone, and judging from the documentation it's still not there. I know it's a feature that can become a nuisance rather than a joy, but I'd still like them to let us make that judgement call ourselves (after all we can still make obnoxious games if we wanted to).
  • 0

#14 cotycrg

cotycrg

    GMC Member

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

Posted 05 April 2012 - 11:57 AM

//checks for holding, even if out of 'bounds' //this is so that if the user starts holding the analog stick and moves their finger out of the bounds, it doesn't ignore the touch, it keeps following until THAT finger is lifted! (works on C++ runner too!)

Some time ago I was working on a comparable interface, but rather the 4-way and 8-way classical joysticks, forcing the visible stick to go into the cardinal and ordinal directions based on the joystick type required. A downside however is that fingers aren't very accurate, and tend to slide further than the joystick can reach. I too solved this by simply keeping the joystick pushed until the finger was lifted (and only following if it came into the detection areas).

But what I really would love to do be able to give off a very short vibration once the stick touches the perimeter, as if it is touched. It would be a short signal to inform the player that moving their finger further away will only increase the distance from the base (degrading his accuracy and reaction speed) as well as give the joystick a more solid feel through subtle force feedback. I understood that there are reservations within YYG to put functions in GM:Studio to buzz the phone, and judging from the documentation it's still not there. I know it's a feature that can become a nuisance rather than a joy, but I'd still like them to let us make that judgement call ourselves (after all we can still make obnoxious games if we wanted to).

I would also love this. Have you ever played with N64oid? They do a similar thing, and it is very helpful. The trick is to barely vibrate on the tick of the tap, and to barely vibrate when reaching the limit. It's also a nice effect for buttons themselves, on the touchscreen.

Though, it's always good to have an in-game option for the user to turn it up/down/off. Everyone's opinions on that matter seem varied.
  • 0

#15 Smarty

Smarty

    GMC Member

  • Retired Staff
  • 7213 posts
  • Version:GM:Studio

Posted 05 April 2012 - 12:04 PM

I would also love this. Have you ever played with N64oid? They do a similar thing, and it is very helpful. The trick is to barely vibrate on the tick of the tap, and to barely vibrate when reaching the limit. It's also a nice effect for buttons themselves, on the touchscreen.

No I haven't, but it is good to know that it is already a proven concept.

Though, it's always good to have an in-game option for the user to turn it up/down/off. Everyone's opinions on that matter seem varied.

Obviously. Speaking of which, when having controls such as the one you developed you also might want to give the players some accuracy and sensitivity parameters to play with.
  • 0

#16 adam2386

adam2386

    GMC Member

  • New Member
  • 2 posts
  • Version:Unknown

Posted 05 April 2012 - 05:52 PM

Quick question, Lets say I was to make the background bigger so the ship could navigate throughout a map. I have been messing around and when I do that, the analog moves off screen and doesn't stay in the corner to be able to follow the ship.

BTW, way nice example!
  • 0

#17 cotycrg

cotycrg

    GMC Member

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

Posted 05 April 2012 - 11:13 PM

Quick question, Lets say I was to make the background bigger so the ship could navigate throughout a map. I have been messing around and when I do that, the analog moves off screen and doesn't stay in the corner to be able to follow the ship.

BTW, way nice example!

Ah, I forgot about that.

Simply add view_xview[0 or 1 or 2..] to everything that has to do with yoyo_mousex and view_yview with everything that has to do with yoyo_mousey. Also add view_xview to everything drawn on the x coordinate and so on and so on.

It'd make it follow the screen. If you don't understand, I could update the example.
  • 0

#18 Robert3DG+

Robert3DG+

    VR Games

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

Posted 06 April 2012 - 12:44 AM

Example updates are always fun.

Been reading through the code trying to develop a lighter version for crappier phone processors, but as it stands I think the original is fine Posted Image
  • 0

#19 BenRK

BenRK

    Now in high-definition!

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

Posted 07 April 2012 - 04:48 AM

This is the issue I'm having with the help file. Those YoYo functions used in this example are not listed in the help file, at least not everywhere I've looked. SOME are, like the virtual keys and stuff, but those YoYo mouse functions for multi touch? I wish I had known about those, hmmmm?

Maybe I'm just looking in the wrong spot, but if ALL the YoYo functions were listed in the YoYo function section, then there wouldn't be an issue, would there?
  • 0

#20 cotycrg

cotycrg

    GMC Member

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

Posted 08 April 2012 - 01:47 AM

This is the issue I'm having with the help file. Those YoYo functions used in this example are not listed in the help file, at least not everywhere I've looked. SOME are, like the virtual keys and stuff, but those YoYo mouse functions for multi touch? I wish I had known about those, hmmmm?

Maybe I'm just looking in the wrong spot, but if ALL the YoYo functions were listed in the YoYo function section, then there wouldn't be an issue, would there?

The help file hasn't been updated properly yet. It should be around the time GM:S is released. For now, the new functions only show up in that autocorrect thing in the code editor boxes.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users