0

我能够让精灵旋转正常,但是位图向下移动了很多并切断了一些图像,尤其是在向下看和任何角度时。我正在切换旋转很多的位图。例如,当你攻击它时,它会在四个攻击图像之间切换。在图像的最后一帧,精灵剑伸出并指向前方,精灵中心点与原始第一帧不攻击时不同。我的印象是这应该无关紧要,因为它仍然应该从位图的中心旋转,而与英雄的位置无关。还是我需要重置翻译点什么的。但是,如果我错了,请纠正我。这是我正在使用的代码。请指教。

  public void draw(Canvas canvas, int pointerX, int pointerY) {
        // setBitmap(MainGamePanel.testIcon);
        如果(设置旋转){
            画布.保存();
            m.reset();
            // 根据操纵杆获取忍者的旋转
            m.setTranslate(spriteWidth / 2, spriteHeight / 2);
            m.postRotate((float) GameControls.getRotation(), spriteWidth / 2,
                    精灵高度 / 2);
            // 旋转忍者
            flipedSprite = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(),
                    bitmap.getHeight(), m, true);
            // 为旋转的忍者设置新的位图
             设置位图(翻转精灵);
            设置旋转 = 假;
            画布.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); }
4

1 回答 1

0

我通过使原始图像大一点来给它更多旋转空间来修复它。虽然不是最好的解决方案,但对我有用。

于 2011-03-20T07:00:42.227 回答