-1

I'm using java with slick2d library and trying to move tile by tile with dynamic speed. I have tried a couple methods but none of them can move with dynamic speed between the tiles. Can someone help me with that and give some examples?

edit:

this two methods have I tried

move with out delta

        movementSpeed = 2;

    //decide direction
    if(targetX != x)
    {
        animation.update(delta);
        if(originalX < targetX)
            x += movementSpeed;
        else if(originalX > targetX)
            x -= movementSpeed;
    }
    if(targetY != y)
    {
        animation.update(delta);
        if(originalY < targetY)
            y += movementSpeed;
        else if(originalY > targetY)
            y -= movementSpeed;
    }

lerp

    public static float lerp(float start, float stop, float t)
    {
        if (t < 0)
            return start;

        return start + t * (stop - start);
    }
    public void move(long delta)
    {
            if (procentMoved == 0)
        {
            if (getSpeed(targetX, targetY) != 0)
            {
                movementSpeed = getSpeed(targetX, targetY);
            } else
            {
                targetX = originalX;
                targetY = originalY;
            }

        }
        if (procentMoved < 1)
        {
            animation.update(delta);

            //              movementSpeed = getSpeed(targetX, targetY);

            procentMoved += movementSpeed;

        } else if (procentMoved > 1)
        {
            animation.update(delta);
            //TODO fix bouncing bug
            procentMoved = 1;
        }

                    + movementSpeed);

        x = lerp(originalX, targetX, procentMoved);
        y = lerp(originalY, targetY, procentMoved);

        if (x == targetX)
            ;
        originalY = x;
        if (y == targetY)
            ;
        originalY = y;
}
LW001
  • 2,452
  • 6
  • 27
  • 36
  • what have you tried? what problems are you facing? provide some code that shows your problem... – Marco Forberg May 10 '13 at 11:17
  • I have tried use lerp, the problem with that was if the speed wasn't correct the char moved to long en needed correction. I have also tried moving with out delta, but if the the movement speed wasn't a multiple of 32(Tile size) it lost its orientation. – user1240988 May 10 '13 at 11:24

1 Answers1

0

It seems as if this could be your issue. Your if statements are just closing and not really doing its part. Also, you're variables are mixed up as well.

if (x == targetX)
        ; // This will skip the If statement
    originalY = x;
    if (y == targetY)
        ; // This will skip the If statement
    originalY = y;

}

In all reality you're saying

orginalY = x; // Y = X?
orginalY = y; // Y = Y

Please do not take this to heart. I'm still having this issue as well, however I'm having to do some corrections and auto placements in order for this to work correctly.

Twister1002
  • 559
  • 1
  • 9
  • 26