java - How to count the number of collisions with collidesWith() in JavaME? -


i'm developing game javame , need count number of collisions in game. i'm using collideswith() method, , i'm doing this:

private void checkcollision()  {        if (spboy.collideswith(spball, true)) {             this.collides++;             if (this.collides == 3) {                 //here show game on image.             }                     }           } 

as can see, if number of collisions 3, game over, can't count number of collisions, because when increment this.collides, automatically have 3 collisions in 1 time.

i'm assuming you're calling checkcollision() inside main loop. means gets called 30-60 times per second. if 2 sprites doesn't move @ during second, there 30-60 collisions - because it's true in each cycle. wanna add timer spboy sprite can't hurt.

int safetimer = 0; int timesincelastloop; // add calculation loop  private void checkcollision() {  safetimer-= timesincelastloop;  if (spboy.collideswith(spball, true) && safetimer<=0) {   this.collides++;   safetimer=3000; // wait 3 seconds till vulnerability   if (this.collides == 3) {    //here show game on image.   }                  }           } 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -