I made a compass app but the rotation of the image is not as smooth as I want it to be. Is there any way it could be made smoother?
P.s , I am a noob so the code might not be that neat or professional as to say.
P.s , I am a noob so the code might not be that neat or professional as to say.
B4X:
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim sensor As PhoneOrientation
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 Label1 As Label
Dim compass As Bitmap
Dim cv As Canvas
Dim destrect As Rect
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("Layout1")
Activity.LoadLayout("layout2")
sensor.StartListening("sensor")
compass.Initialize(File.DirAssets , "compass.png")
cv.Initialize(Activity)
destrect.Initialize(0dip,30dip,320dip , 320dip)
End Sub
Sub Activity_Resume
sensor.StartListening("sensor")
End Sub
Sub Activity_Pause (UserClosed As Boolean)
sensor.StopListening
End Sub
Sub sensor_OrientationChanged (Azimuth As Float, Pitch As Float, Roll As Float)
Label1.Text = Azimuth
Dim degrees As Float
degrees = 360-Azimuth
cv.DrawBitmap(compass , Null , destrect)
cv.DrawBitmapRotated(compass , Null ,destrect, degrees)
Activity.Invalidate
End Sub
End Sub