Moving an Actor in a Sprite background with MoveToAction in Scene2D
<p>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.</p>

<p><a href="https://i.stack.imgur.com/SOFtd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SOFtd.png" alt="enter image description here"></a></p>

<p>I'm using actor as moving character because I can implement moving animation easily using <code>MoveToAction</code>. (As far as I know)</p>

<p>I'm not sure if this is the best implemetation. If there is a better way please let me know. </p>

<p>Ok what I've done so far is;</p>

<p>I'have a class extended from <code>ApplicationAdapter</code>.</p>

<p>This is my Actor class;</p>

<pre><code>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());
    }
}
</code></pre>

<p>So I want to move this (joffrey) from one box to another using MoveToAction when user Swipes right, left, up, down.</p>

<p>I created a class SimpleDirectionGestureDetector as told in here;
<a href="https://stackoverflow.com/questions/15185799/libgdx-get-swipe-up-or-swipe-right-etc">LibGDX - Get Swipe Up or swipe right etc.?</a></p>

<p>And here is how I used the class;</p>

<pre><code>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);
        }
    }));
</code></pre>

<p>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!</p>

<p>Do you have any idea what am I mising here?</p>

<p>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 ?</p>

<p>Thanks fo any help.</p>