如何在更改方向时使样本蛇应用程序的头部向左或向右转

时间:2013-10-10 17:48:26

标签: android rotation png sample

我正在尝试更改android示例蛇应用程序的代码,当我按下右三角形并且蛇向右转时,.png文件(我认为它被称为'yellowstar.png')旋转90度和副Versa。我用一个真正的蛇头图像取代了yellowstar.png,但目前的情况是,当蛇向右转时,蛇头保持在同一个“北面”方向。 对不起那个非特定的问题..我试着指定它们,所以你知道我的意思..

我更新了Snakehead的PNG,现在我有4个PNG。 (左起;抬头;右转;头朝下)头部使用的PNG取决于蛇的移动方向。有4个类(Backgroundview,Snake,SnakeView,TileView),我不知道在哪里加载我的4个新PNG。

问题:

1.是否可以使用setTile()命令实现arkocal的建议?

2.如果Q#1是正确的:这是放置它的正确位置??:

//Figure out which way the snake is going, see if he's run into anything (the
//walls,himself, or an apple). If he's not going to die, we then add to the front 
//and subtract from the rear in order to simulate motion. If we want to grow him, we 
//don't subtract from the rear.

private void updateSnake() {
    boolean growSnake = false;

    // Grab the snake by the head
    Coordinate head = mSnakeTrail.get(0);
    Coordinate newHead = new Coordinate(1, 1);

    mDirection = mNextDirection;

    switch (mDirection) {
        case EAST: {
            newHead = new Coordinate(head.x + 1, head.y);
            break;
        }
        case WEST: {
            newHead = new Coordinate(head.x - 1, head.y);
            break;
        }
        case NORTH: {
            newHead = new Coordinate(head.x, head.y - 1);
            break;
        }
        case SOUTH: {
            newHead = new Coordinate(head.x, head.y + 1);
            break;
        }
    }

3.如果这是错误的地方,请告诉我把它放在哪里

感谢您的回答,

于连

1 个答案:

答案 0 :(得分:0)

最简单的解决方案是手动旋转(复制4次并使用任何图像编辑程序旋转它们)图像,因为只需要无限(4)次旋转。然后你可以加载这些图像而不是在java中做一些图形工作。