Hi
(sorry for my poor English)
While I was creating a game Arkanoid, I realized that this did not work well on some devices.
The ball slows down and speeds up suddenly for no apparent reason
The real reason for my concern is that this strange behavior does not always happen but it happens only in a few moments. Especially when you first start after installation.
I have access to these three devices:
ASUS NEXSUS 7 (very Good)
SAMSUNG S2 (good)
HUAWEI Y300 (bad)
I thought that the reason depended on the speed of the device
so I decided to do flow analysis to adjust timer and speed according to the speed of the devices
the body of the code is something like this
the results were
NEXSUS 15-22 ms but some time 30-40
S2 15-22 but some time 25-45
HUAWEI 20-35 but some time 40-150
I thought then that something was wrong in my code such that there were exceptions that would slow down the loop. Then I decided to do a test on loop.
I set the timer to 1 second to give time to the cycle to finish
Surprise!
There are still oscillations even without a body : (
You can try it yourself
Some of you I know how to explain the reason for this strange behavior?
And how to remove?
I understand the delay of 1-2 ms but not ms 20-30-40
This depends on the other tasks running on the device?
Set the timer to 100ms is not nice for arkanoid. Effect GameBoy first : P
(sorry for my poor English)
While I was creating a game Arkanoid, I realized that this did not work well on some devices.
The ball slows down and speeds up suddenly for no apparent reason
The real reason for my concern is that this strange behavior does not always happen but it happens only in a few moments. Especially when you first start after installation.
I have access to these three devices:
ASUS NEXSUS 7 (very Good)
SAMSUNG S2 (good)
HUAWEI Y300 (bad)
I thought that the reason depended on the speed of the device
so I decided to do flow analysis to adjust timer and speed according to the speed of the devices
the body of the code is something like this
B4X:
Sub TimerHome_Tick 'interval 30ms
lasttime=DateTime.Now
'Step ball
'Calc Collision
'destroy bricks
'
'......
Dim c As Int
c=DateTime.Now-lasttime
label1.Text=c ' time in ms
End Sub
the results were
NEXSUS 15-22 ms but some time 30-40
S2 15-22 but some time 25-45
HUAWEI 20-35 but some time 40-150
I thought then that something was wrong in my code such that there were exceptions that would slow down the loop. Then I decided to do a test on loop.
B4X:
Sub Process_Globals
Dim timer1 As Timer
End Sub
Sub Globals
Dim label1 As Label
Dim maxtime As Int
Dim lasttime As Int
End Sub
Sub Activity_Create(firsttime As Boolean)
timer1.Initialize("timer1",1000)
label1.Initialize("label1")
Activity.AddView(label1,50%x,50%y,15%x,10%y)
label1.TextColor=Colors.Red
timer1.Enabled=True
maxtime=0
End Sub
Sub timer1_Tick
lasttime=DateTime.Now
For i = 0 To 1500
For j = 0 To 1500
'delay
Next
Next
Dim c As Int
c=DateTime.Now-lasttime
label1.Text=c
End Sub
I set the timer to 1 second to give time to the cycle to finish
Surprise!
There are still oscillations even without a body : (
You can try it yourself
Some of you I know how to explain the reason for this strange behavior?
And how to remove?
I understand the delay of 1-2 ms but not ms 20-30-40
This depends on the other tasks running on the device?
Set the timer to 100ms is not nice for arkanoid. Effect GameBoy first : P