0
所以,我正在研究一个2d塔防游戏,并且需要敌人的精灵在他们改变方向时进行旋转。我知道这可以使用内置的Java旋转/仿射变换方法轻松完成,但为了优化/性能,我想知道是否可以用像素数组来旋转。旋转像素阵列
感谢
所以,我正在研究一个2d塔防游戏,并且需要敌人的精灵在他们改变方向时进行旋转。我知道这可以使用内置的Java旋转/仿射变换方法轻松完成,但为了优化/性能,我想知道是否可以用像素数组来旋转。旋转像素阵列
感谢
盖洛德, 我不知道,如果你还在这里寻找一个答案,但对其他成员的缘故,这里是我能够用它来解决类似的问题。我一直在构建一个游戏引擎,它利用了与你所描述的相似的图形结构。我使用的旋转功能是这样的: 所有的花车都可以用双打替换,而且可能更好。我使用浮点数来帮助低端计算机的性能。
float cos = (float)Math.cos(-angle);//The angle you are rotating (in radians)
float sin = (float)Math.sin(-angle);//The angle you are rotating (in radians)
float sWidth = screenWidth/2;
float sHeight = screenHeight/2;
float pWidth = pixelArrayWidth/2;
float pHeight = pixelArrayHeight/2;
for each pixel in screen{
int xPosition = pixelIndexX - sWidth;
int yPosition = pixelIndexY - sHeight;
int tx = (int)(xPosition * cos - yPosition * sin);
int ty = (int)(xPosition * sin + yPosition * cos);
xPosition = tx + pWidth;
yPosition = ty + pHeight;
if((xPosition is out of bounds) or (yPosition is out of bounds)) continue;
setPixelAt(screenPixelX, screenPixelY, pixelArray[xPosition + yPosition * pixelArrayWidth])
}
我知道它与psuedo代码和java代码是拼凑的,但它应该是可以理解的。如果任何人需要澄清,只需发表评论并询问。
重复http://stackoverflow.com/questions/2799755/rotate-array-clockwise – 2013-03-05 03:40:00
这不是一个2d数组。我正在使用一维数组来保存像素数据。该帖子的评论似乎与我的问题毫无关系。 – GayLord 2013-03-05 03:54:30
我的不好!你能举一个例子输入和输出吗?如果你只是从像[1,2,3,4,5]到[3,4,5,1,2]这样的数组旋转,那么这是一个容易解决的问题。请让我知道你在找什么。 – 2013-08-04 17:05:56