Android Question Game animation speed

hookshy

Well-Known Member
Licensed User
Longtime User
I have problems setting speed in one game. It is about fruits that drop from sky and it seems I do not understand how to control the speed .
I use the folowing statement:
fructe(i).y=fructe(i).y+speed
where speed is set by a user option as slow , normal, fast and the values ranges from 1dip,3dip,6dip
the refresh time is done as the canvas refresh itself on Sub AcSf_Update(ElapsedTime As Long)

It would be great to have the game speed up automaticaly as the users plays more and more ....

The problem I have is that from device to device the speed does not feet at all ...
either is is to small at that begining that becomes to boring
or it is to fast at the end and it becomes to dificult to play
:(
I think I would need some advice ..as I can not find any solution to ajust speed game.
Thank your for your time.
 

strat

Active Member
Licensed User
Longtime User
Did you try to use timer at small interval? Speed may be equal at all devices if position changes in the timer.
 
Upvote 0

Linostar

Member
Licensed User
Longtime User
Try to calculate the number of frames per seconds. Look at the code in any of GameView tutorials to know how to calculate it.
(For example: http://www.b4x.com/android/forum/threads/gameview-create-2d-android-games-part-i.20038/)

The number of frames per seconds (FPS) will give you an idea about the animation & rendering speed of your device, where the higher the FPS the higher your device speed is, and vice versa. You can take this value into consideration when calculating your "fructe" speed.
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
Try to calculate the number of frames per seconds. Look at the code in any of GameView tutorials to know how to calculate it.
(For example: http://www.b4x.com/android/forum/threads/gameview-create-2d-android-games-part-i.20038/)

The number of frames per seconds (FPS) will give you an idea about the animation & rendering speed of your device, where the higher the FPS the higher your device speed is, and vice versa. You can take this value into consideration when calculating your "fructe" speed.
This code gives erroneous results so forget it (this has been discussed in the past in this forum). The perf_* examples of the Accelerated Surface lib show how to display the FPS reliably.
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
I have problems setting speed in one game. It is about fruits that drop from sky and it seems I do not understand how to control the speed .
I use the folowing statement:
fructe(i).y=fructe(i).y+speed
where speed is set by a user option as slow , normal, fast and the values ranges from 1dip,3dip,6dip
the refresh time is done as the canvas refresh itself on Sub AcSf_Update(ElapsedTime As Long)

It would be great to have the game speed up automaticaly as the users plays more and more ....

The problem I have is that from device to device the speed does not feet at all ...
either is is to small at that begining that becomes to boring
or it is to fast at the end and it becomes to dificult to play
:(
I think I would need some advice ..as I can not find any solution to ajust speed game.
Thank your for your time.
You will find answers in my tutorial about games. See the chapter "Mind the step".
 
Upvote 0

hookshy

Well-Known Member
Licensed User
Longtime User
I've solved the problem . Thanks.
Sometimes it is a bit hard to understand and I would have little question to clear myself.
object.x=object.x+myspeed*acsf.ElapsedTimeSinceLastDraw/1000

From where comes 1000 ... Is this factor should be proportional or ajusted to the number of objects you are drawing ?

I understand that if ElapsedTime is bigger that means -Device is slowed down
Is this correct ?

Thank you
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
I've solved the problem . Thanks.
Sometimes it is a bit hard to understand and I would have little question to clear myself.
object.x=object.x+myspeed*acsf.ElapsedTimeSinceLastDraw/1000

From where comes 1000 ... Is this factor should be proportional or ajusted to the number of objects you are drawing ?

ElapsedTimeSinceLastDraw is in milliseconds, so 1000 converts the value to seconds. Thus, the speed is expressed in pixels by seconds. If you want to keep it in pixels/ms or choose a different unit, it's up to you. You will have to adapt the value of MySpeed to your unit. That's all.

I understand that if ElapsedTime is bigger that means -Device is slowed down
Is this correct ?

If ElapsedTimeSinceLastDraw becomes bigger, that means that either the device is slowed down or your code needed more time to run (that happens for example when new enemies comes into play).
 
Upvote 0

hookshy

Well-Known Member
Licensed User
Longtime User
Thanks a lot for your explanations .
Makeing games is sometimes a lot more fun than doing other applications , all thought people in these days is playing candy crash and do not have time to test other games , I still love coding for games.
I am looking forward to test libGDX .
Thank you for your time .. hope to come one day with a donation as some of your products are missing from my library , as I must upgrade the b4a but did not found the good moment yet as I am low on resurses.
 
Upvote 0
Top