Ok i'm gonna teach you guys how to do this.
First you are going to open Sprite.java and add this:
Code:
public int movingX , movingY = 0;
public boolean movedEnough = false;
private boolean startedMoving = false;
/**
* Used to make sprites move
* @param finalCoordX
* The final X coord of the sprite
* @param finalCoordY
* The final Y coord of the sprite
* @param startingX
* The starting X coord of the sprite
* @param startingY
* The starting y coord of the sprite
* @param speed
* How fast the sprite will move
* @param coordToMove
* Which coord to move? x? y? or both?
* @param advancedSprite
*/
public void drawMovingSprite(int finalCoordX, int finalCoordY,int startingX, int startingY,
int speed, char coordToMove, boolean advancedSprite) {
if(!startedMoving) {
movingX = startingX;
movingY = startingY;
startedMoving = true;
}
if(!movedEnough) {
if(coordToMove == 'y')
movingY += speed;
if(coordToMove == 'x')
movingX += speed;
if(coordToMove == 'b') {
movingX += speed;
movingY += speed;
}
if((speed < 0 ? movingX <= finalCoordX : movingX >= finalCoordX) && (coordToMove == 'x' || coordToMove == 'b')) {
movingX = finalCoordX;
movedEnough = true;
}
if((speed < 0 ? movingY <= finalCoordY : movingY >= finalCoordY) && (coordToMove == 'y' || coordToMove == 'b')) {
movingY = finalCoordY;
movedEnough = true;
}
setSprite(coordToMove == 'y' ? startingX : movingX,coordToMove == 'x' ?
startingY : movingY, advancedSprite);
} else
setSprite(coordToMove == 'y' ? startingX : movingX, coordToMove == 'x' ?
startingY : movingY, advancedSprite);
}
public void setSprite(int spriteX, int spriteY, boolean advancedSprite) {
if(advancedSprite)
drawAdvancedSprite(spriteX, spriteY);
else
drawSprite(spriteX, spriteY);
}
Now imagine you want to make your login Box move:
Sprite loginBox = new Sprite(DIRECTORY);
Now where you draw your loginscreen you would do something like this:
loginBox.drawMovingSprite(FINAL X COORD, FINAL Y COORD, STARTING X COORD, STARTING Y COORD, SPEED, 'coordToMove', IS IT AN ADVANCED SPRITE?);
*FINAL COORDS - This is where you set the final coordinates which means when the sprite stops moving it will stand at those coordinates.
*STARTING COORDS - This is where you set the starting coordinates which means the sprite will start moving from those coordinates and will keep moving until it reaches the final coordinates.
*SPEED - that is pretty obvious, it's the speed you want the sprite to move.
*coordToMove - 'x', 'y', 'b' - This is where you choose what coordinate do you want to play with the x coord or y coord or even both.
This works pretty nicely, but i think it can get a few improvements, feel free to do them yourself