我有一个正方形的 2d 精灵数组,我试图将它们全部围绕地图的中心位置旋转,但经过多次尝试,精灵似乎只围绕它们自己的中心旋转.这可能吗?
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?
首先想到的是,如果我理解你的问题,你告诉所有精灵必须旋转的点在哪里:sprite.setOrigin(yourPointVector2.x, yourPointVector2.y);
sprite.rotation(yourRotation);
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);
编辑新的为您的评论编辑
1 次精灵旋转的简单测试,也许不是最好的方法,但我现在想到了.这样可以帮助您,如果您的精灵位于地图的 50.50,并且地图的中心为 400、240,我将创建一个变量来存储精灵的初始位置,
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,
示例:
//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);
这篇关于LibGDX - 围绕它们的中心旋转一个 2d 精灵数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!