LibGDX - 围绕它们的中心旋转2d精灵数组 [英] LibGDX - Rotate a 2d array of sprites around their center

查看:143
本文介绍了LibGDX - 围绕它们的中心旋转2d精灵数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个正方形的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都必须在哪里旋转:
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精灵数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆