0

I have a problem to get an identical ball speed across different android devices. Its an outbreakgame with a bouncing ball. I have developed the app on my galaxy s7 but when testing it on my s3 the ball and other objects are approx 30% faster, or something ???.

  • I am using a surfaceview and the framerate is constant that is about 60fps
  • the ballspeed is set in termns of dp and stored as a xml-resource. (same with ball radius)

     <dimen name="ballSpeed">5dp</dimen>
     <dimen name="ballRadius">6.25dp</dimen>
    

I simply retrieve the field stored in the resource-file

float ballSpeed = createGC.getContext().getResources().getDimensionPixelSize(R.dimen.ballSpeed);

and then pass ballspeed to the ball-objects constructor

So how could the speed difference be explained? fps is the same an speed and radius are expressed in dpi. But somehow the speed for the Samsung Galaxy s3 faster. I guess it could have to do with the screensize.

s7 inch: 5.1
s3 inch: 4.8

So my questions are:

Could the different screensizes be the explanation to he difference in speed? And how could I possibly take this into account?

java
  • 1,165
  • 1
  • 25
  • 50

2 Answers2

0

As explained in here, dp doesn't have the same size on every screen. You could change your unit in function of that.(like in, mm or pt for example)

Community
  • 1
  • 1
Dimitri Bosteels
  • 381
  • 4
  • 12
0

What is criterion of different speed? Balls moves different pixels amount or parts of display?

This criterion affects what size unit to select for ball speed. If ball should travel same part of screen, may be dp is best way. If it should travel same phisical distance (for example inch) use in or pt.

Ircover
  • 2,406
  • 2
  • 22
  • 42