Auf Thema antworten

Grüße!


Vor kurzem habe ich angefangen, mich in Slick2D einzuarbeiten. Ich habe eine Animation, bestehend aus 4 einzelnen Bildern erstellt und kann diese auf dem Frame abspielen lassen. So weit so gut. Nun möchte ich noch Tastatur-Input einbauen, um die Animation mit den WASD Tasten auf dem Frame zu verschieben. Leider bewegt sich die Animation nicht, obwohl ich ein Input-Objekt mit entsprechenden if-Abfragen erzeugt habe. Vielleicht könntet ihr mir ja helfen, den Fehler zu finden?

[code=Java]

import org.newdawn.slick.Animation;

import org.newdawn.slick.AppGameContainer;

import org.newdawn.slick.BasicGame;

import org.newdawn.slick.GameContainer;

import org.newdawn.slick.Graphics;

import org.newdawn.slick.Input;

import org.newdawn.slick.SlickException;

import org.newdawn.slick.Image;


public class TestMain extends BasicGame{

        Input in;

        int x = 50;

        int y = 50;

        Image [] images = new Image [4];

        Animation anim;

       

    public TestMain(String title) {

        super(title);

    }

   

    @Override

    public void init(GameContainer gC) throws SlickException {

        in = gC.getInput();

        images[0] = new Image("Images/walk.png");

        images[1] = new Image("Images/walk2.png");

        images[2] = new Image("Images/walk3.png");

        images[3] = new Image("Images/walk4.png");

        anim = new Animation(images,150);

    }

   

   

    public void update(GameContainer gC, int ar) throws SlickException {

        if (in.isKeyPressed(in.KEY_W)); {

            y -= 3;

        }

       

        if (in.isKeyPressed(in.KEY_S)); {

            y += 3;

        }

       

        if (in.isKeyPressed(in.KEY_A)); {

            x -= 3;

        }

       

        if (in.isKeyPressed(in.KEY_D)); {

            x += 3;

        }

    }

   

    @Override

    public void render(GameContainer gC, Graphics g) throws SlickException {

        g.fillRect(0, 0, gC.getWidth(), gC.getHeight());

        g.drawAnimation(anim, x, y);

    }

   

    public static void main (String [] args) throws SlickException {

        try {

            AppGameContainer app = new AppGameContainer(new TestMain("asdasd"));

            app.setDisplayMode(800, 600, false);

            app.setVSync(true);

            app.setTargetFrameRate(60);

            app.start();

        } catch (SlickException e) {}

    }

}

[/code]


Schon einmal danke für eure Hilfe :)



Oben