0

I am developing a platform game using AndEngine. Character keeps running and collect coins. I am playing sound when character collides with some coin. It works fine when coins are in horizontal sequence and are at some distance relative to each other. But when character collides with bunch of coins, character jerks and game slow downs the body's velocity. Character's speed suddenly comes close to zero.enter image description here

Character's sprite is connected to a physics body and I am settings its speed using body.setLinearVelocity() method. Here is how I am detecting collision of sprite and coins and playing sound.

protected void checkCoinCollisions() {
    for(int i = mCoins.size() - 1; i >= 0; i--) {
        Coin coin = mCoins.get(i);
        if(hero.collidesWith(coin)) {
            mCoinsCollected++;
            mScene.detachChild(coin);

            coinSound.play();

            mCoins.remove(coin);
        }

    }
}

Any idea how to remove this slowdown of character and jerk?

Khawar Raza
  • 15,870
  • 24
  • 70
  • 127
  • So you're saying that if you compare the value returned by GetLinearVelocity before and after calling that function, it's different? – iforce2d Jul 02 '14 at 15:02
  • no actually, before colliding with coins, it runs smoothly, but after collision, it slow downs suddenly. – Khawar Raza Jul 02 '14 at 15:58
  • You already mentioned that. I'm talking about the value returned by GetLinearVelocity... does it change after you call checkCoinCollisions? – iforce2d Jul 02 '14 at 16:08

0 Answers0