Ok currently I have a game piece object at position 1,1 and I move it to position 5,4. Its just a simple repaint from there to here.
But in my move() call I want to animate the piece sliding on the board. I already do simple move calls to float text or move a card in straight lines. But its always only on one axis, either x or y.
And the moving of a game piece can be at any odd angle. So what type of equation should I be looking to use to figure out my where to redraw the gamepiece as it slides along the board.
I current brain storm was something like this.
void setDestination(int destX, int destY) {
this.destX = destX;
this.destY = destY;
if(currentX < destX){
moveX = 1;
}else{
moveX = -1;
}
if(currentY < destY){
moveY = 1;
}else{
moveY = -1;
}
moving = true;
}
void move() {
if(moving == false) return;
if(currentX != destX)
currentX += moveX;
if(currentY != destY)
currentY += moveY;
if(currentX == destX && currentY == destY)
moving = false;
}
Is there a better way to do this?
