I am trying to make my sprite start moving from the moment it is created and do its animation. It draws on the screen right and animates but doesn't move. It should start moving towards the direction it is facin this means right and if collision detected to stop the animation do whatever and continue the animation. Here is my code:
public class grt extends ApplicationAdapter {
Misheva mshv;
@Override
public void create () {
mshv = new Misheva();
mshv.init();
}
@Override
public void render () {
mshv.drawIt();
mshv.act(Gdx.graphics.getDeltaTime());
}
@Override
public void dispose() {
mshv.disposer();
}
}
Misheva.java
public class Misheva extends Actor {
int state;
TextureAtlas atl;
TextureRegion [] walk;
SpriteBatch batch;
Animation anim;
float stateTime;
float elapsed = 0;
int horizontalspeed = 10;
public void reset (){
state = 0;
stateTime = 0;
}
@Override
public void act(float delta) {
super.act(delta);
stateTime += delta;
switch(state){
case 0: setX(getX()-horizontalspeed*delta);
}
}
public void drawIt(){
Gdx.gl.glClearColor(1, 1, 1, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
elapsed += Gdx.graphics.getDeltaTime();
batch.draw(anim.getKeyFrame(elapsed,true), 0, 0);
batch.end();
}
public void init (){
atl = new TextureAtlas(Gdx.files.internal("data/tomaton.atlas"));
batch = new SpriteBatch();
walk = new TextureRegion[3];
walk[0]=atl.findRegion("tomato");
walk[1]=atl.findRegion("t_walk2");
walk[2]=atl.findRegion("t_walk1");
anim = new Animation(1/10f,walk);
}
protected void disposer(){
batch.dispose();
atl.dispose();
}
}