I'm trying to develop a game which has a background consists of 4*4 box created as texture. And I have an actor which is moving in the boxes. It is like 2048 game. But I have just one character that will move around.
I'm using actor as moving character because I can implement moving animation easily using MoveToAction
. (As far as I know)
I'm not sure if this is the best implemetation. If there is a better way please let me know.
Ok what I've done so far is;
I'have a class extended from ApplicationAdapter
.
This is my Actor class;
public class MyActor extends Actor {
Texture texture = new Texture(Gdx.files.internal("joffrey.png"));
public boolean started = false;
public MyActor() {
setBounds(imageWidth / 2, imageHeight / 2, texture.getWidth() / 2, texture.getHeight() / 2);
}
@Override
public void draw(Batch batch, float alpha) {
batch.draw(texture, this.getX(), getY());
}
}
So I want to move this (joffrey) from one box to another using MoveToAction when user Swipes right, left, up, down.
I created a class SimpleDirectionGestureDetector as told in here; LibGDX - Get Swipe Up or swipe right etc.?
And here is how I used the class;
Gdx.input.setInputProcessor(new SimpleDirectionGestureDetector(new SimpleDirectionGestureDetector.DirectionListener() {
@Override
public void onUp() {
moveAction = new MoveToAction();
moveAction.setPosition(myActor.getX(), myActor.getY() + imageHeight);
moveAction.setDuration(0.1f);
myActor.addAction(moveAction);
}
@Override
public void onRight() {
moveAction = new MoveToAction();
moveAction.setPosition(myActor.getX() + imageWidth, myActor.getY());
moveAction.setDuration(0.1f);
myActor.addAction(moveAction);
}
@Override
public void onLeft() {
moveAction = new MoveToAction();
moveAction.setPosition(myActor.getX() - imageWidth, myActor.getY());
moveAction.setDuration(0.1f);
myActor.addAction(moveAction);
}
@Override
public void onDown() {
moveAction = new MoveToAction();
moveAction.setPosition(myActor.getX(), myActor.getY() - imageHeight);
moveAction.setDuration(0.1f);
myActor.addAction(moveAction);
}
}));
Everything looks fine until here. When I launch the app it is working fine at the beginning but after some moves the moving action look so laggy and then suddenly application is closed without any error message or anything and nothing in the logcat!
Do you have any idea what am I mising here?
Moreover, is this the right way to implement a moving action ? Do I have to use Actors to be able to give moving animation to a texture ?
Thanks fo any help.