Span sprite at different intervals

Forget the previous one if you saw it.

public void createNormZomb(){ 

                normZombie.add(createSprite(R.drawable.zombie1));
                normZomb.postDelayed(this, 1000);
            }

@Override
public void run() {
    normZombie.add(createSprite(R.drawable.zombie1));
    normZomb.postDelayed(this, 1000);

}

So basically I do what I want. Every 1 second, it spawns another zombie. The only drawback is when it works like 30 seconds or something like that, it forces you to close. Until that goes, everything is fine. (FYI implements Runnable at the top) If anyone has any ideas as to why the power will close after so much time, I would really appreciate it.

(As a remark, if someone knows what I should do for this reason, I'm used to using xml. How to display the score and timer on the screen in code, since I do not use xml. Be a good way to write a timer that counts in seconds .)

Thanks everyone :)

+3
source share
1

, time = 5. x % 5, 5. 23 5, 4, 3, 23 = 4*5 + 3. 23 % 5 = 3. , ( ..):

protected void onDraw(Canvas canvas) {
  canvas.drawColor(Color.BLACK);
  for (int i = 0; i < temps.size(); i++) {
  //or was there a reason to do the loop backwards...?
    temps.get(i).onDraw(canvas);
  }

  for (Sprite sprite : normZombie) {//for each normZombie do:
    //for(int i=0; i<normZombie.size();i++) no need to loop again, right?

    long startTime=System.currentTimeMillis();                      
    long elapsed=(System.currentTimeMillis() - startTime) / 1000;
    int time = 3;//,0,1,2 or 4
    if(elapsed % 5 == time)
      sprite.onDraw(canvas);
    }
  }

private void createSpritesNorm(){         
  for (int i = 0; i < 12; i++) {
    normZombie.add(createSprite(R.drawable.zombie1));//do this 12 times
  }
}
+2

All Articles