LibGDX - Rotate a 2d array of sprites around their center(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.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 精灵数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:LibGDX - 围绕它们的中心旋转一个 2d 精灵数组
基础教程推荐
- 修改 void 函数的输入参数,然后读取 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 存储 20 位数字的数据类型 2022-01-01
