B4A Library JoyStick - another Joystick library for Gamers

It wraps this Github project. It allows control of the Angle and Power. When the value of any one of the above changes it will raise an event in the B4A project and return the current angle, power, and angle in degrees to the B4A project (see sample project). Colors are fully customizable. Sure you will figure out the returned values and how to use them (i.e angle, power, and angle in degrees). The dragable button will auto centre when not touched.

This project also allows you to set the Joystick pad (foreground and background) with drawables. See the below images - the Joystick on the left is composed making use of drawables in the B4A projects /Object/res/drawable folder. The Joystick on the right is "standard issue".

The attached project will print the returned values to the B4A log when the Joysticks are moved
Posting the B4A project and the B4A library files.



Sample code:
#Region  Project Attributes
    #ApplicationLabel: JoyStick
    #VersionCode: 1
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private js1 As JoyStick
    Private js2 As JoyStick
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    js1.ButtonDrawable = "button"
    js1.PadBackground = "pad"
    js2.ButtonColor = Colors.Yellow
    js2.PadColor = Colors.Blue

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub js1_value_changed(angle As Double, angleDegrees As Double, powr As Double)
    Log("js1 angle = " & angle)
    Log("js1 angleDegrees = " & angleDegrees)
    Log("js1 power = " & powr)
    Log(" ")
End Sub

Sub js2_value_changed(angle As Double, angleDegrees As Double, powr As Double)
    Log("js2 angle = " & angle)
    Log("js2 angleDegrees = " & angleDegrees)
    Log("js2 power = " & powr)
    Log(" ")
End Sub


Github: erz05, Wrapped by: Johan Schoeman
Version: 1
  • JoyStick
    • value_changed (angle As Double, angleDegrees As Double, power As Double)
    • ba As BA
    • BringToFront
    • DesignerCreateView (base As PanelWrapper, lw As LabelWrapper, props As Map)
    • Initialize (EventName As String)
    • Invalidate
    • Invalidate2 (arg0 As Rect)
    • Invalidate3 (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • IsInitialized As Boolean
    • RemoveView
    • RequestFocus As Boolean
    • SendToBack
    • SetBackgroundImage (arg0 As Bitmap)
    • SetColorAnimated (arg0 As Int, arg1 As Int, arg2 As Int)
    • SetLayout (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • SetLayoutAnimated (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int, arg4 As Int)
    • SetVisibleAnimated (arg0 As Int, arg1 As Boolean)
    • enableStayPut (enable As Boolean)
    • onMove (cv As JoyStick, angle As Double, power As Double)
    • Angle As Double [read only]
    • AngleDegrees As Double [read only]
    • Background As Drawable
    • ButtonColor As Int [write only]
    • ButtonDrawable As String [write only]
    • Color As Int [write only]
    • Enabled As Boolean
    • Height As Int
    • Left As Int
    • PadBackground As String [write only]
    • PadColor As Int [write only]
    • Power As Double [read only]
    • Tag As Object
    • Top As Int
    • Visible As Boolean
    • Width As Int
See also this one:


  • JoyStickLibFiles.zip
    7.2 KB · Views: 360
  • b4aJoyStick.zip
    14.1 KB · Views: 369
Last edited: