I am developing a android game in surfaceView. When i test the game on different devices the playerSprite seems to go faster on some devices as compared to the other.
How do i accomodate for different devices when setting player speed programmatically?
if(MainActivity.slowSpeed == true){
speedX = (float) (canvasWidth/266);
speedY = (float)(canvasHeight/150);
}
if(MainActivity.fastSpeed == true){
speedX = (float) (canvasWidth/192);
speedY =(float) (canvasHeight/108);
}
When the framerate is not steady (like 30 or 60 frames a second), you should compensate every moving element in your game by a factor which you calculate from the actual framerate you achieved.
You use it somewhere in your game as such:
So everywhere where something is moving, you compensate the movement by this factor. This way on a machine which is capable of 60 frames a second, everything will just move twice as slow per frame, which results in the game moving at exactly the same speed.
Make sure your framerate calculation is done EVERY frame, and must be done with an adequate precision.