I've developed a game with AndEngine GLES2-AnchorCenter with Box2d ext for android. To make the player jump I use a vector2, see code below :
@Override
public boolean onSceneTouchEvent(Scene pScene,
TouchEvent pSceneTouchEvent) {
if (pSceneTouchEvent.isActionDown()) {
awalx = pSceneTouchEvent.getX();
awaly = pSceneTouchEvent.getY();
return true;
}
if (pSceneTouchEvent.isActionMove()) {
return true;
}
if (pSceneTouchEvent.isActionUp() && loncat == false) {
akhirX = pSceneTouchEvent.getX();
akhirY = pSceneTouchEvent.getY();
jarakX = (awalx - akhirX) / 20;
jarakY = (awaly - akhirY) / 20;
Vector2 jump = new Vector2(jarakX, jarakY);
body.setLinearVelocity(jump);
// mSound2.play();
lct--;
loncat = true;
return true;
}
return true;
}
You can see that I use variables jarakX
and jaraxY
to measure the jumping distance. When I play the game for the first time vector2 is running perfectly, but when I exit the game and play again, vector2 seems to make the player jump shorter than the first time.
Vector2 in the third game even is shorter than the second game, and so on. Is it because the performance of AndEngine or box2d or maybe the activity in backgroud affecting AndEngine and box2d?