精灵是在背景下绘制的

时间:2014-12-23 03:02:13

标签: java slick2d

我在Slick2D开发StateBasedGame(仅用于学习目的),我遇到了问题。

walkingRight.draw(0,250);

此动画在背景精灵下绘制。我不知道如何让它成为最重要的。我根本看不到它。

完整代码:

    package gamelogic;

import org.lwjgl.input.Mouse;
import org.newdawn.slick.*;
import org.newdawn.slick.gui.MouseOverArea;
import org.newdawn.slick.state.*;

public class Level extends BasicGameState {

    // INITIATE IMAGES
    public Image background;
    public Image title;
    public Image playButton;
    public Image exitButton;

    public Animation walkingRight;
    public Animation playerIdle;
    public int[] duration = {200, 200, 200, 200, 200};
    public int durationIdle[] = {200, 200}; 


    // INITIATE VARIABLES FOR TITLE'S POSITION
    public float menuPosX;
    public float menuPosY;

    public Player player;

    // __CONSTRUCTOR
    public Level(int state) {

    }

    public void init(GameContainer gc, StateBasedGame sbg) throws SlickException {
        background = new Image("res/levelbg.png");
        Image[] walkRight = { new Image("res/player/snap0.png"), new Image("res/player/snap1.png"),
                new Image("res/player/snap2.png"), new Image("res/player/snap3.png"), new Image("res/player/snap4.png")};
            Image idle[] = { new Image("res/player/snap0.png"), new Image("res/player/snap1.png")};

            this.walkingRight = new Animation(walkRight, this.duration, false);
            this.playerIdle = new Animation(idle, this.durationIdle, false);        

    }

    public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException {
        background.draw(0,0);
        playerIdle.draw(0,0);
    }

    public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException {
        Input input = gc.getInput();

            walkingRight.draw(0,250);

    }   

    public int getID() {
            return 1;
        }   
    }

你能帮帮我吗?

1 个答案:

答案 0 :(得分:1)

好的,我找到了解决方案。不应在update()函数中绘制动画,而应仅使用变量作为坐标在render()函数中绘制一次。在update()函数中,您将更改坐标,并为动画变量分配不同的动画。