Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Real time menus and controls

Jmv38Jmv38 Mod
edited October 2012 in Code Sharing Posts: 3,297

Hello all. To work on my ''planet'' project i need some workbench to manage all the code variants. So i needed some menus (many menus actually), but real time menus because i develop a real time game, and many of the solutions posted here are not real time compatible (i mean ''zero FPS'' cost). So i've coded a solution and added it to my last package of real-time controllers. For those interested, here is the video:

And here is the code:

PS: if you grab the code, please add a comment. I've no idea if this is used by anyone, and if no one does, i'll just stop posting code.


  • Posts: 140

    .@Jmv38... Just wanted to say thanks for the optimized menus and sliders. :)

  • Posts: 371

    .@Jmv38, Awesome code! But you have an error (pretty sure it is in the virtualStick:vector() function) where if you move the stick, and put it back to the starting position, pos becomes vec2(nan, nan)

  • SimeonSimeon Admin Mod
    Posts: 5,705

    Interesting and minimal controls, @Jmv38. Thank you for sharing them.

  • Jmv38Jmv38 Mod
    Posts: 3,297

    Thanks a lot Jordan! Sometimes i was losing the slider but i didn't know why... You've got it. I've corrected it (not in the link): the :normalize() can be done only if the vector length is >0... I'll correct it in a future release. If you need it now, replace the following function:

    function VirtualStick:vector()
        local stickRange = self.radius - self.deadZoneRadius
        local stickAmount = math.max(self.stickOffset:len() - self.deadZoneRadius, 0)
        local stickDirection = self.stickOffset
        if stickDirection:len()>0 then  stickDirection = self.stickOffset:normalize() end
        return stickDirection * (stickAmount/stickRange)
  • Posts: 1,284

    Joysticks that appear wherever you tap the screen seem like an extremely common thing for games to need.

    It’s a pain to get this off Dropbox, so I’ve given it an icon and am putting it here as a zip.

Sign In or Register to comment.