OSJ - Part 1

Previous topic - Next topic

MrTAToad

OSJ (or On-screen Joystick) is a way of emulating a joystick on devices that dont have any joysticks.

This routine enables the test rectangle to be moved in the direction of the joystick and at a speed based on the distance from the centre.  I've included the Android, Palm and Windows version.

The Android one (on my phone at any rate) has a tendency not to detect movement - most likely the device is way too slow to reliably poll for mouse input.

The next part will be to put in multi-touch and buttons

[attachment deleted by admin]

Ian Price

#1
Sounds cool - can we use the code and/or graphics in our own projects? :)

Oh, there's no code :(

Works well though =D
I came. I saw. I played.

MrTAToad

No code yet!

trucidare

nice idea - you can create a gbal for these input touch things
MacBook Pro 2,2 GHz Core 2 Duo, 4 GB RAM, 160 GB HDD, 8600M GT
Core i3 - 3,07 GHz, 8 GB Ram, 2.5 TB HDD, Geforce GTX 260+ OC

spacefractal

You need to press on the center first where the joystick is, before you can move it. In the real time, that can been pretty annoyring and slowdown the control of the game.

The joystick should just pull into the nearst direction where I pressed in some sort of distance.

Also you putted this to the Code Snippets forum with no code......
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation - The beagle Jam - Cave Heroes 2023 - https://spacefractal.itch.io/

MrTAToad

#5
Yes, you need to press over the joystick to be able to move it.

QuoteThe joystick should just pull into the nearst direction where I pressed in some sort of distance.
I presume you mean when you click over the base and not the joystick - it might be an idea, but its not normal, as far as I know

QuoteAlso you putted this to the Code Snippets forum with no code......
I've added the current source code now - didn't have room earlier.

I'm going to setup a Joystick Control File which will allow seperation of the joystick base, knob and shadow, plus allow positioning of buttons (will support up to 9)

[attachment deleted by admin]

spacefractal

its can been pretty annoying if nothing happens becaues you a not precision pressed on the center (etc you came to release your finger). Then I actuelly prefer either its reposition its self on the touch (seen in some games, like Age of Zombies or Epic Citadal), or just point to the neast position where the finger is (when touched on base or near it).
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation - The beagle Jam - Cave Heroes 2023 - https://spacefractal.itch.io/

MrTAToad

It will re-center itself one the image is released.  I'll look it into later on...

spacefractal

apart from that, its does works very well, but did only tested with mouse :-D.
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation - The beagle Jam - Cave Heroes 2023 - https://spacefractal.itch.io/

MrTAToad

Thanks!  This will need to be thoroughly checked as, with any luck, it will become the standard for GLBasic programs :)

spacefractal

its not perfect onscreen and of course some thing need to been improvements...

- Joystick should not autos center itself when finger touched down and move joystick out of the edge. Its should first autocenter around 20-25% larger edge than the base its self.
- Output should of course been -1 to 1 and not from -60 to 60 (this due all normal Joystick commands does that and me think should do the same here). This could been easy done in UpdateX() and UpdateY().
- MouseState() should been first of the control() and not to last. When its below, there would been one frame delay, before something happens, and I dont like that. Its a easy fix :-D
- Scaling support and Multitouch of course.

The most major issue is really the first one about auto center, which would been much much better onscreen joystick when fixed.. But its still a great start to do a great analog onscreen joystick support. I have not coded such of one, because my secret game is not need that, but I more using angles rather than collosions boxes, even for digital joystick (2way, 4way and 8way).
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation - The beagle Jam - Cave Heroes 2023 - https://spacefractal.itch.io/

MrTAToad

It will autocentre if there is no movement within the base - I've added a bit where you can just press within there and the joystick will automatically move to the correct place.

The -60 - +60 is the valid area around the base that the joystick can be position.  This can change according to the size of the joystick base used, and isn't used as an output.


spacefractal

I diddent notice that etc, when I checked the code.

Then I guess its should been detected as the image used, rather doing maunally use the 60 value, but more detected the size of the base as well the knop it self. This would make sure any joystick base at any size could been used too... and then have some sort of scaling support.

Just some ideas.
Genius.Greedy Mouse - Karma Miwa - Spot Race - CatchOut - PowerUp Elevation - The beagle Jam - Cave Heroes 2023 - https://spacefractal.itch.io/

MrTAToad

The latter bit is something I added later.

Scaling support may be an idea, but could slow things down.