2011-03-20 52 views
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); }

回答

0

我通过使原始图像稍大一点以增加旋转空间来修复它。虽然不是最好的解决方案,但为我工作。