【问题标题】:rotation help in androidandroid中的旋转帮助
【发布时间】:2011-07-19 00:21:34
【问题描述】:

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

 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);

}

【问题讨论】:

    标签: android rotation translate-animation


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2012-07-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多