Sub Class_Globals
Private Root As B4XView
Private xui As XUI
Private pnlTest As B4XView
Private cvsTest As B4XCanvas
Private bmcTest As BitmapCreator
Private xFont As B4XFont
Private rctText, rctDest As B4XRect
End Sub
Public Sub Initialize
' B4XPages.GetManager.LogEvents = True
End Sub
'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("MainPage")
cvsTest.Initialize(pnlTest)
bmcTest.Initialize(pnlTest.Width, pnlTest.Height)
Draw
End Sub
Private Sub Draw
xFont = xui.CreateDefaultFont(20)
cvsTest.DrawRect(cvsTest.TargetRect, xui.Color_Red, True, 1)
rctText = cvsTest.MeasureText("Test", xFont)
bmcTest.Initialize(rctText.Width, rctText.Height)
bmcTest.FillGradient(Array As Int(xui.Color_Blue, xui.Color_Magenta, xui.Color_Blue), bmcTest.TargetRect, "LEFT_RIGHT")
rctDest.Initialize(100dip + rctText.Left, 50dip + rctText.Top , 100dip + rctText.Right, 50dip + rctText.Bottom)
cvsTest.DrawBitmap(bmcTest.Bitmap, rctDest)
cvsTest.DrawText("Test", 100dip, 50dip, xFont, xui.Color_Yellow, "LEFT")
End Sub
Private Sub btnRun_Click
Private NewAngle, Duration As Int
NewAngle = Rnd(360, 1800)
Duration = NewAngle * 2
NewAngle = -NewAngle
Snap = True
btnRun.Enabled = False
AnimateTo(Angle + NewAngle, Duration)
End Sub
Great and thank you.... Mr. KlausSure !
Add this line
NewAngle = -NewAngle
in the btnRun_Click routine.
B4X:Private Sub btnRun_Click Private NewAngle, Duration As Int NewAngle = Rnd(360, 1800) Duration = NewAngle * 2 NewAngle = -NewAngle Snap = True btnRun.Enabled = False AnimateTo(Angle + NewAngle, Duration) End Sub
Private Sub SetLocker
Private a, d As Int
a = Abs(Angle)
d = Abs(DeltaAngle)
a = a Mod d
Select a
Case 0, 1, 2, 3
lblReference.Rotation = 0
Case 4
lblReference.Rotation = -35 * Direction
Case 5
lblReference.Rotation = -55 * Direction
Case 6, 7, 8, 9
lblReference.Rotation = -65 * Direction
Case Else
lblReference.Rotation = 0
End Select
End Sub
Private Sub SetLocker
Private a, d As Int
a = Abs(Angle)
d = Abs(DeltaAngle)
a = a Mod d
Select a
Case 0, 1
lblReference.Rotation = 0
Case 2
lblReference.Rotation = -10 * Direction
Case 3
lblReference.Rotation = -20 * Direction
Case 4
lblReference.Rotation = -35 * Direction
Case 5
lblReference.Rotation = -55 * Direction
Case 6, 7, 8, 9
lblReference.Rotation = -65 * Direction
Case Else
lblReference.Rotation = 0
End Select
End Sub
the results are pretty decent, thank you...It seems that you want to combine the simple wheel project with the other one from HERE.
Maybe try something like this:
B4X:Private Sub SetLocker Private a, d As Int a = Abs(Angle) d = Abs(DeltaAngle) a = a Mod d Select a Case 0, 1 lblReference.Rotation = 0 Case 2 lblReference.Rotation = -10 * Direction Case 3 lblReference.Rotation = -20 * Direction Case 4 lblReference.Rotation = -35 * Direction Case 5 lblReference.Rotation = -55 * Direction Case 6, 7, 8, 9 lblReference.Rotation = -65 * Direction Case Else lblReference.Rotation = 0 End Select End Sub
When i saw the project it reminded me something.
Attached a modified version with text.
View attachment 140348
Is related to CurrentSectorIndex or this AnimateTo(New, 500) New = New Mod 360Probably yes.
You have the source code, try it.
Then you need to think about from what condition you want stop and how.
Private Sub SnapRotation
If Snap = True Then
Private New As Int
Select ReferencePosition
Case "12 o'clock"
If (90 Mod DeltaAngle) = 0 Then
New = (Floor(Angle / DeltaAngle) + 0.5) * DeltaAngle
Else
New = (Floor(Angle / DeltaAngle + 0.5)) * DeltaAngle
End If
End Select
AnimateTo(New, 500)
New = New Mod 360
CurrentSectorIndex = Angle Mod 360
Select ReferencePosition
Case "12 o'clock"
CurrentSectorIndex = 270 - CurrentSectorIndex
End Select
If CurrentSectorIndex < 0 Then
CurrentSectorIndex = CurrentSectorIndex + 360
End If
......
End Sub
I want to stop the wheel, according to the number that I have specified, for example I want the wheel to stop exactly at number 8 or number 10What exactly do you want to know or understand ?
When the animation is finished, the position of the wheel is not aligned with the center of the sector.
SnapRotation does this alignment.