复合精灵如何与 libgdx 一起缩放
How composite sprites scale together with libgdx
我合成了我的 sprite 来构建一辆带有可定制保险杠、驾驶室、扰流轮等的巨型卡车。容纳这些 Sprite
的 class 是 MTruck
,我可以绘制它完美地提供了我保持比例 1.0.
mWheels.setPosition(posX + 17 * scale, posY);
mCab.setPosition(posX + 22 * scale, posY + 7 * scale);
mFender.setPosition(posX, posY + 75 * scale);
mWheels
位于卡车的 y 原点,mFender
位于 x 原点。
我已经尝试了各种比例值并将其与我应用于 mWheels
、mCab
等的比例分开提取,但发生的只是精灵比例,但它们的位置变得不对齐.
如果我不能破解它,我将不得不渲染到一个纹理并按我的比例缩放。
或许,Set origin 可以帮到您:
void setOrigin(float originX, float originY)
Sets the origin in relation to the sprite's position for scaling and
rotation.
float getOriginX()
The origin influences setPosition(float, float),
setRotation(float) and the expansion direction
of scaling setScale(float, float)
float getOriginY()
The origin influences setPosition(float, float),
setRotation(float) and the expansion direction of
scaling setScale(float, float)
新编辑: 例如,如果您在菜单上自定义车辆,那么在这之后自定义车辆并在运行时创建图像并缩放是可行的,在 Sprite 中使用此图像,因为它可能更容易,但这只是一个想法
我合成了我的 sprite 来构建一辆带有可定制保险杠、驾驶室、扰流轮等的巨型卡车。容纳这些 Sprite
的 class 是 MTruck
,我可以绘制它完美地提供了我保持比例 1.0.
mWheels.setPosition(posX + 17 * scale, posY);
mCab.setPosition(posX + 22 * scale, posY + 7 * scale);
mFender.setPosition(posX, posY + 75 * scale);
mWheels
位于卡车的 y 原点,mFender
位于 x 原点。
我已经尝试了各种比例值并将其与我应用于 mWheels
、mCab
等的比例分开提取,但发生的只是精灵比例,但它们的位置变得不对齐.
如果我不能破解它,我将不得不渲染到一个纹理并按我的比例缩放。
或许,Set origin 可以帮到您:
void setOrigin(float originX, float originY)
Sets the origin in relation to the sprite's position for scaling and rotation.
float getOriginX()
The origin influences setPosition(float, float),
setRotation(float) and the expansion direction
of scaling setScale(float, float)
float getOriginY()
The origin influences setPosition(float, float),
setRotation(float) and the expansion direction of
scaling setScale(float, float)
新编辑: 例如,如果您在菜单上自定义车辆,那么在这之后自定义车辆并在运行时创建图像并缩放是可行的,在 Sprite 中使用此图像,因为它可能更容易,但这只是一个想法