LibGDX - Rotate a 2d array of sprites around their center

非 Y 不嫁゛ 提交于 2019-12-02 14:36:05

问题


I have a square 2d array of sprites and im trying to rotate all of them around the center position of the map, but after many attempts the sprites seem to be only rotating around their own center. Is this possible?


回答1:


the first thing that comes to mind is, if I understand your question, you tell all sprites where is the point which must rotate using: sprite.setOrigin(yourPointVector2.x, yourPointVector2.y); sprite.rotation(yourRotation);

Edit new edited for your comment

simple test for 1 sprite rotation, maybe is not the best way but it occurred to me that right now.

Like this helps you, if your sprite is at 50.50, of the your map, and the center of your map is 400, 240, I would create a variable that will store the initial position of the sprite,

example:

//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);


来源:https://stackoverflow.com/questions/27555023/libgdx-rotate-a-2d-array-of-sprites-around-their-center

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!