Real time menus and controls

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.

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

.@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)

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

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)

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.