0

I want to draw/render my sprite 2 seconds after a collision.

How can I make it ?

If i do in that way the render add a new ButtonOrange immediately.

@Override
public void render(SpriteBatch batch)
{
    relation.add(new ButtonOrange(coordinates,text);
    relation.get(0).update();
    relation.get(0).draw(batch);

    if(relation.get(0).collission() == true)
        relation.remove(0);
}
3

You can use a temporary timer variable to store time elapsed since collision and if its greater than 2 second, draw that sprite.

boolean flag = false;
float time = 0; //timer for 2 sec

@Override
public void render(SpriteBatch batch)
{
    if(body.collision == true)   //just a dummy code to check for collision
      flag = true;               //set flag to true if collided

    if(flag == true)
    {
      //keep track how much time has elapsed
      time += Gdx.graphics.getDeltaTime();     

      if(time > 2)           //if more than 2 sec
        sprite.draw(batch);       //draw sprite
    }

}
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.