Android : Why is this jump() method for a sprite not working?

on Sunday, October 26, 2014


My game only has 2 classes right now, "MyGdxGame" and "Player". I've added a method jump() to my Player class and overridden the touchDown() method to call jump every time the screen is tapped:



public void jump() {

startTime = TimeUtils.nanoTime();
elapsedTime = TimeUtils.timeSinceNanos(startTime);

boolean jumpTime = elapsedTime < 2000000001;

while (jumpTime) {
moveBy(xSpeed, ySpeed);
}
moveBy(xSpeed, -ySpeed);
}

@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
//moveBy(xSpeed, ySpeed);
jump();
return true;
}


right now when the screen is tapped the sprite goes up but doesn't come back down. before the screen is tapped the sprite is moving from left to right at constant speed xSpeed. any ideas?


edit: I built my project then ran it again. it freezes when I tap the screen then crashes lol


0 comments:

Post a Comment