简体   繁体   English

Android libgdx,适用于不同屏幕尺寸的固定变量

[英]Android libgdx, fixed variable for different screen sizes

Android, libgdx. 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. 如果使用box2d,则只需应用线速度。

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 https://stackoverflow.com/a/42317348/3445320

And you should also consider this 你也应该考虑一下
https://xoppa.github.io/blog/pixels/ https://xoppa.github.io/blog/pixels/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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