LibGDX - 围绕其中心旋转2d精灵阵列

时间:2014-12-18 20:22:24

标签: java libgdx

我有一个正方形的2d精灵阵列,我试图围绕地图的中心位置旋转所有这些,但经过多次尝试后,精灵似乎只围绕自己的中心旋转。 这可能吗?

1 个答案:

答案 0 :(得分:0)

首先想到的是,如果我理解你的问题,你会告诉所有的精灵,必须使用以下几点旋转: sprite.setOrigin(yourPointVector2.x, yourPointVector2.y); sprite.rotation(yourRotation);

为评论编辑

编辑新

对1个精灵旋转的简单测试,可能不是最好的方法,但它现在发生在我身上。 enter image description here 这样可以帮助你,如果你的精灵位于地图的50.50处,地图的中心是400,240,我会创建一个存储精灵初始位置的变量,

示例:

//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);
相关问题