开发者

rotation help in android

I am able to get the sprite to rotate okay however the bitmap gets shifted down a lot and cuts off some of the image especially when looking down and to any angle. I am switching the bitmap that gets rotated a lot. Like for example when you attack it switches between four attacking images. On the last frame of the image the sprites sword is out and pointed forward and the sprites center point is not the same as the original first frame when he was not attacking. I am under the impression this should not matter because it should still rotate from the center of the bitmap and not matter where the hero is. Or do I need to reset the translate point or something. But please correct me if I am wrong. here is the co开发者_如何学Pythonde I am using. Please Advise.

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


I fixed it by making the original image a little bit bigger to give it more space to rotate. Although not the best solution but works for me.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜