when you push any joystick it equals something around 8 or -8
huh?
@OWI, that's going to be tricky with a virtual joystick because they emulate digital joysticks with a range between -1.0 and 1.0 but the idea would otherwise be along the lines of :
+ Code SnippetSetErrorMode(2)
// set window properties
SetWindowTitle( "Joy1" )
SetWindowSize( 1280,720, 0 )
SetWindowAllowResize( 1 )
// set display properties
SetVirtualResolution( 1280,720)
SetOrientationAllowed( 1, 1, 1, 1 )
SetSyncRate( 30, 0 )
SetScissor( 0,0,0,0 )
UseNewDefaultFonts( 1 )
GLOBAL CursorX, LastJoyX
GLOBAL BOARD_SIZE_WIDTH = 20
AddVirtualJoystick(1,200,200,50)
do
Input()
If GetRawKeyState(27) then Exit
Print( CursorX )
print(GetVirtualJoystickX(1))
Sync()
loop
Function Input()
JoyX = GetVirtualJoystickX(1)
if LastJoyX = 0
If JoyX < 0 and CursorX > 0 then DEC CursorX
If JoyX > 0 and CursorX < BOARD_SIZE_WIDTH then INC CursorX
Endif
LastJoyX = JoyX
EndFunction
note the value of GetVirtualJoystickX() when you release it where it
gradually returns to center/0. so, just because you "released" it doesn't mean it's 0/centered/ready for another tap.
but, to detect a move in either direction, you'll need to compare it to "unmoved", somehow.
that being said, if you're intent on using a vjoystick to move the cursor, you may simply want to put a timer on it to "slow it down":
+ Code SnippetSetErrorMode(2)
// set window properties
SetWindowTitle( "Joy1" )
SetWindowSize( 1280,720, 0 )
SetWindowAllowResize( 1 )
// set display properties
SetVirtualResolution( 1280,720)
SetOrientationAllowed( 1, 1, 1, 1 )
SetSyncRate( 30, 0 )
SetScissor( 0,0,0,0 )
UseNewDefaultFonts( 1 )
GLOBAL CursorX
GLOBAL BOARD_SIZE_WIDTH = 20
AddVirtualJoystick(1,200,200,50)
do
If LastMove# + 0.5 <= Timer()
Input()
LastMove# = Timer()
Endif
If GetRawKeyState(27) then Exit
Print( CursorX )
print(GetVirtualJoystickX(1))
Sync()
loop
Function Input()
If GetVirtualJoystickX(1) < 0 and CursorX > 0 then DEC CursorX
If GetVirtualJoystickX(1) > 0 and CursorX < BOARD_SIZE_WIDTH then INC CursorX
EndFunction