0
votes

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?

1
from where comes lct ? - ZEE
lct is limitation number of jumps. Every single game scene has only 3-5 times chance of jumping. lct has no correlation with vector2. - thedhenis
Are you clearing the world completely, and starting again the next time with a brand new world exactly the same? When you log the value of the 'jump' vector, does it really become shorter as the title of your question says, or is it the same but just the result is different? Does the problem still happen when you use a hardcoded value for the 'jump' vector? - iforce2d
When i restart the application, vector giving the same result like what i need. The problem is only appear when i restart the game scene / activity without exit from the application. But, this problem already solved by using fixedstepphysicsworld. I'm not sure what is the real problem, but maybe caused by difference in framerate andengine with box2d. Thanks. - thedhenis

1 Answers

0
votes

Thaks for all, my problem solved by using fixedstepphysicsworld