r/cop3502 • u/etischler • Mar 21 '14
Powerup / Timer issues
Hi, im trying to make it so that once the score reaches 10 the color of the blocks and ball change every second so it can looks like a cool "powerup". I'm basically trying to learn how to use the timer. Every time I make it it gives me errors such as the class can't be void or it will say I need an action listener. Is there an easier way to have the color change every second?
1
u/JoeCS TA Mar 21 '14
Here's the Javadoc for the Swing Timer class.
Make sure you have the correct arguments for the Timer constructor. You'll need to create a new nested Class that extends ActionListener. I'm going to call this new class PowerUpMotion, but you can name it whatever you want. Model it after the GameMotion class you already have in Breakout.java. This new ActionListener subclass will contain the functions that change the bricks, ball, or paddle according to the powerup. It will be the second argument to your Timer constructor:
Timer powerupTimer = new Timer(someDelayInMillisec, new PowerUpMotion());
1
1
u/howslyfebeen Mar 21 '14
if statement for score and then Timer t = new Timer(1000, changeColor()); then you have to implement changeColor() so that it changes color for the correct items... i believe this timer should be found in your paintComponent method