I am trying to accomplish fireworks functionality based on the github code from Lenoids. I want to create two fireworks (one white and another red) and have them display continuously after every two seconds.
Here's what I did so far:
- Created two buttons (one for each color of fireworks). The buttons have the fireworks functionality.
Call the buttons programatically in a thread to display the fireworks.
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_congratulations); new Thread(new Runnable() { @Override public void run() { while(true){ try { Thread.sleep(100); button10.callOnClick(); //for red fireworks button11.callOnClick(); //for white fireworks } catch (InterruptedException e) { e.printStackTrace(); } } } }).start(); }
The problem is that if I increase the value of sleep method, then the fireworks do not show up at all. How can I accomplish the two second continuous fireworks functionality?
Here's the fireworks code:
new ParticleSystem(MyClass.this, 100, R.drawable.star_pink, 800) .setSpeedRange(0.1f, 0.25f) .oneShot(view, 70);
If you want to run the firework every two seconds then use Handler instead of the thread and thread.sleep.
Hope that helps.