简体   繁体   中英

How to make sure the speed in every android device is same for an android game?

I am working on a game and i am moving the background images by 4px. For this i had used a normal mdpi screen of 480X800. i have designed the game using this resolution.

To support different resolution i have used for Horizontal speed width/480. so, for 240X400 resolution the background image will move with 2px speed half of the 480X800. Same done for the the vertical speeds. But for some reason in 240X400 it moves faster then it is expected. I want to design it in such a way that no other player gets advantage due to its resolution.

Note: I am designing this using only processing & android. Screen-orientation - LANDSCAPE

You should fix your scrolling speed in DP (eg 10dp per second). Then you can read device DP using

DisplayMetrics metrics = getResources().getDisplayMetrics();
Log.d(LOG_TAG, "density: " + metrics.densityDpi);
int pixelSpeed = (int) (densitySpeed * (metrics.densityDpi / 160));

Then your pixel speed will be different, but physical distance per scroll will be same.

More details in link from @harvey_slash

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM