0
我有一个方形的2D精灵阵列,我试图围绕地图的中心位置旋转它们,但是经过多次尝试后,精灵似乎只是在旋转他们自己的中心。 这可能吗?LibGDX - 围绕它们中心旋转一个2D精灵阵列
我有一个方形的2D精灵阵列,我试图围绕地图的中心位置旋转它们,但是经过多次尝试后,精灵似乎只是在旋转他们自己的中心。 这可能吗?LibGDX - 围绕它们中心旋转一个2D精灵阵列
,想到的第一件事就是,如果我明白你的问题,你告诉所有的精灵在哪里,必须使用旋转点: sprite.setOrigin(yourPointVector2.x, yourPointVector2.y);
sprite.rotation(yourRotation);
编辑新编辑的评论
1个精灵旋转的简单测试,可能不是最好的方法,但它现在发生在我身上。 就像这可以帮助你,如果你的精灵是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);
唯一的问题是,setOrigin相对于精灵的坐标,而不是屏幕 –
@ SK-io的添加信息的评论, –
谢谢,我会尝试你的编辑tomorow。 –