0
我能夠讓精靈旋轉正常,但是位圖會向下移動很多並切斷一些圖像,特別是向下俯視時和任何角度。我正在切換旋轉很多的位圖。例如,當您攻擊它時,會在四個攻擊圖像之間切換。在圖像的最後一幀,精靈劍出來並指向前方,精靈中心點與他未攻擊時的原始第一幀不同。我覺得這應該不重要,因爲它仍然應該從位圖的中心旋轉,而不管英雄在哪裏。或者我需要重置翻譯點或其他東西。但是如果我錯了,請糾正我。這裏是我使用的代碼。請指教。 在android中的旋轉幫助
public void draw(Canvas canvas, int pointerX, int pointerY) {
// setBitmap(MainGamePanel.testIcon);
if (setRotation) {
canvas.save();
m.reset();
// get rotation for ninja based off of joystick
m.setTranslate(spriteWidth/2, spriteHeight/2);
m.postRotate((float) GameControls.getRotation(), spriteWidth/2,
spriteHeight/2);
// rotate ninja
flipedSprite = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(),
bitmap.getHeight(), m, true);
// set new bitmap to rotated ninja
setBitmap(flipedSprite);
setRotation = false;
canvas.restore();
}
// create the destination rectangle for the ninjas animation pointerX
// and pointerY are from the joystick moving the ninja around
destRect = new Rect(pointerX, pointerY, pointerX + spriteWidth,
pointerY + spriteHeight);
canvas.drawBitmap(bitmap, getSourceRect(), destRect, null);
}