Java LibGDX-围绕精灵的中心旋转2d精灵阵列
我有一个正方形的2d精灵阵列,我试图围绕地图的中心位置旋转所有精灵,但经过多次尝试后,精灵似乎只围绕自己的中心旋转。Java LibGDX-围绕精灵的中心旋转2d精灵阵列,java,libgdx,Java,Libgdx,我有一个正方形的2d精灵阵列,我试图围绕地图的中心位置旋转所有精灵,但经过多次尝试后,精灵似乎只围绕自己的中心旋转。 这可能吗?首先想到的是,如果我理解你的问题,你可以告诉所有精灵必须旋转的点在哪里,使用: sprite.setOrigin(yourPointVector2.x,yourPointVector2.y) sprite.rotation(你的旋转) 编辑新内容为您的评论编辑 一个精灵旋转的简单测试,也许不是最好的方法,但我现在想到了。 这样可以帮助你们,若你们的精灵在地图的50.50
这可能吗?首先想到的是,如果我理解你的问题,你可以告诉所有精灵必须旋转的点在哪里,使用:
sprite.setOrigin(yourPointVector2.x,yourPointVector2.y)代码>
sprite.rotation(你的旋转)代码>
编辑新内容为您的评论编辑
一个精灵旋转的简单测试,也许不是最好的方法,但我现在想到了。
这样可以帮助你们,若你们的精灵在地图的50.50,地图的中心是400240,我会创建一个变量来存储精灵的初始位置
例如:
//is stored only once, because if not will store where you are during rotation
yourVectorPosInicial.x = sprite.getX();
yourVectorPosInicial.v = sprite.getY();
yourVectorCenterMap.x = 400f;
yourVectorCenterMap.y = 240f;`
youtSprite.setOrigin(yourVectorCenterMap.x-yourVectorPosInicial.x ,
yourVectorCenterMap.y-yourVectorPosInicial.y);
//this in your Draw or update render
sprite.rotation(10f);
唯一的问题是setOrigin是相对于精灵坐标的,而不是相对于screen@sk-io为您的评论添加信息,