简体   繁体   中英

Android libgdx, fixed variable for different screen sizes

Android, libgdx. I'm currently working on a game shooting a basketball, my problem was my throw velocity variable is fixed and when i tried it to a different devices w/ different screen size, the result was failed.
Any solution? Thanks for the help!

float throwVelocity=Gdx.graphics.getWidth()*0.905f;

Velocity is vector quantity should depend on width and height both.

If you're using box2d then you just need to apply linear velocity.

float speed,angle;

Vector2 startingVelocity =new Vector2(speed,speed);
startingVelocity.rotate((float) angle - 45);

body.setLinearVelocity(startingVelocity);

speed and angle is provided by you.

Taken reference from :
https://stackoverflow.com/a/42317348/3445320

And you should also consider this
https://xoppa.github.io/blog/pixels/

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