libgdx плавное движение

Ответить
voodoo_child
Сообщения: 1
Зарегистрирован: 17 авг 2015, 11:14

libgdx плавное движение

Сообщение voodoo_child » 17 авг 2015, 11:15

Сделал движение врага по заданным точками, но спрайт при движении дергается, при этом fps 55-60. Вот код:

Код: Выделить всё

public void update(float dt, SpriteBatch sb) {
        moveEnemy(dt);
        drawEnemy(sb);
    }

    private void drawEnemy(SpriteBatch sb) {
        enemySprite.draw(sb);
    }
    
    private void moveEnemy(float dt) {
        float eX = enemySprite.getX();
        float eY = enemySprite.getY();

        position.set(eX, eY);

        if(pathPoints.size > 0) {
            
            destination.set(pathPoints.peek().x * sizeX, (Gdx.graphics.getHeight() - sizeY) - (pathPoints.peek().y * sizeY));

            if(Math.round(eX) == destination.x && Math.round(eY) == destination.y) {
                destination = pathPoints.pop();
            }

            dir.set(destination.x, destination.y).sub(eX, eY).nor();
            velocity.set(dir).scl(speed);
            movement.set(velocity).scl(dt);
            position.add(movement);

            enemySprite.setPosition(position.x, position.y);
        }
    }
Подскажите пожалуйста, в чем может быть проблема?

Ответить