Android Question Timers and objects speed in different devices

icebold

Member
Licensed User
Longtime User
Hi,

I am looking for a simple way to fix the following:
I have a timer with .interval=30
In my "tick" sub I make to move a little bitmap image from the top of the screen to the bottom, increasing at each tick the .top image position +1dip vertical ( using gameview ).
The sub works perfectly but I can see speed differences testing it on my 2 phisical devices, both in Portrait mode:
- SAMSUNG S3 : 720x1280, 306ppi
- SONY XPERIA TABLET S : 1280x800, 161ppi

In the tablet the animation is slower than samsung S3.
Why ? I think that density could be the answer ( 306ppi vs 161 ) considering that devices have the same pixel ( 1280 ) in portrait mode but I don't know how to manage it.

Any help is appreciated,
Thanks.
 

thedesolatesoul

Expert
Licensed User
Longtime User
It may not be the density as you are using dips. It may (potentially) be the overall number of pixels.
However, interval = 30ms is pretty tight, if your device isnt fast enough it wont be able to make it 30ms and the timer will actually be called slower.
One way around it (this may be in Informatix's tutorial somewhere), is to scale the distance by the time delta. i.e. store the time in each timer tick, and see the difference between previous tick. Observe it by logging it first and see if that is the problem. If it is then you can know that if the timer is being called 60ms instead of 30ms then you need to move 2dip rather than 1dip.
 
Upvote 0

icebold

Member
Licensed User
Longtime User
It may not be the density as you are using dips. It may (potentially) be the overall number of pixels.
However, interval = 30ms is pretty tight, if your device isnt fast enough it wont be able to make it 30ms and the timer will actually be called slower.
One way around it (this may be in Informatix's tutorial somewhere), is to scale the distance by the time delta. i.e. store the time in each timer tick, and see the difference between previous tick. Observe it by logging it first and see if that is the problem. If it is then you can know that if the timer is being called 60ms instead of 30ms then you need to move 2dip rather than 1dip.

Thanks thedesolatedsoul!
I will do that, observing the time delta between each tick could be a good idea.
So, on slower devices I could change the timer interval in this way:
- timer.interval = 30 --> image.top=image.top+1dip [ fast device ]
- timer.interval = 60 --> image.top=image.top+2dip [ slow device ]
- timer.interval = 90 --> image.top=image.top+3dip [ very slow device ]

in this way the image's animation speed should be the same for devices with different hw performances.
Could dip have decimal? eg. 1,5dip for a timer.interval=45 ?
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
in this way the image's animation speed should be the same for devices with different hw performances.
Could dip have decimal? eg. 1,5dip for a timer.interval=45 ?
I believe so. You can probably use the delta to scale it, for e.g. if 30ms for 1dip then,
moveY = (delta_in_ms/30) * 1dip
 
Upvote 0
Top