Hello. First I'm sorry if my english sounds weird. I'm creating a small animation. There are multiple balls "bouncing" on Frame and if any of them hits a placed special ball, it will grow big and become another special ball (which means any of the rest ball can be special too by hitting any of two special things and repeat again). However a special ball's lifespan is only 3 seconds. The Ball class extends Thread so it can call sleep(3000) and vanished after done. Ball isn't the main class.

The main class puts every balls in an ArrayList. Main class uses Gudradrain's template. Now I want to include Pause feature. When paused the canvas will draw another image and doesnt call update() method. The problem is the sleep(3000) on every ball is still counting so when we back to the animation, all special balls suddenly disappear. How to make all special balls sleep only on non-paused state? in other word, pause the ball's sleep when enter pause state.

my current code goes like that with update() method updating position of the ball then checking for collision where if yes, start the 3seconds countdown and vanished. if no, nothing happen (still 'common' ball bouncing and waitting chance to hit the special). can you please give example code how the ball class wait for 3seconds before vanished but, that wait can be paused and resumed?

the rest as Game class and render() are already same approach like you said

@zoto:so I just need to call fade() when the collision is detected and let the update() method to start counting down by decrement. But in my sight, delta is always changing depends on how long time needed to update, sleep and render (based on template). how about the accuracy so it can vanish on exactly 3scnds?

@zoto:so I just need to call fade() when the collision is detected and let the update() method to start counting down by decrement. But in my sight, delta is always changing depends on how long time needed to update, sleep and render (based on template). how about the accuracy so it can vanish on exactly 3scnds?

anyway thanks for above solution. I try it

Might be a good place to use a Timer to run the gameloop. Or, build in some controls to the gameloop so that the loop time remains steady.

The delta variable is how many milliseconds have passed since the last update.The counter will go a few milliseconds over 3 seconds depending how well the game is running, probably safe to ignore.

On small amount of balls it can be ignored but when I tried with 100 balls even I could sense the difference of fading time from 3scnds it can be fixed if I turn off the AA (less update time) but player also can trigger this AA so time of update can be changed anytime. Should I remove this AA although the circles will look rough? :|

When on applet (java webstart), if the page lose focus (user see other window or tab), do all threads from the applet get paused automaticly or not?

On small amount of balls it can be ignored but when I tried with 100 balls even I could sense the difference of fading time from 3scnds Smiley it can be fixed if I turn off the AA (less update time)

That sounds promising. Just a guess because I can't see your code but is your ball draw function just drawing an image or are you using Graphics2D.draw* or Graphics2D.fill*? If you are not using an image I would advise you switch to either loading an image or draw it once in your code and reuse it.

The program jvisualvm comes with java and is very useful for debugging performance issues.

Quote

but player also can trigger this AA so time of update can be changed anytime.

No code run on the client is safe from tampering.

Quote

Should I remove this AA although the circles will look rough? :|

I wouldn't give up so fast, figure out what you want the computer to do then figure out how to make it do that.

Quote

When on applet (java webstart), if the page lose focus (user see other window or tab), do all threads from the applet get paused automaticly or not?

This is something that has to be coded in, looking over the template it isn't in there. My first place to look for java help is the JavaDoc. You would probably just implement FocusListener on your game class,add this line to the constructor,

Sorry first but I really dont understand about "draw once". They're moving so they just need to be drawn every update right?

That was bad wording on my part. What I was trying to explain is that Graphics2D.drawImage will perform better than a series of drawing commands. When I said draw once what I really meant to say was create the ball image once.

if that's not clear or you don't know how to do it maybe post your current Ball class.

this is my current Ball class which work well by extending Thread (ofc no pause function until here). Dont mind the value variabel and method regarding it, they're optional.

Ball size defaultly is 10 and 100 when become big (turn into special ball). I pass the Graphics2D to each Ball while on render() loop so each Ball can draw itself regarding their positions and color. checkColl() detects for collision to special balls. I save all special balls by their (x,y) of center only, not whole Ball class. That's why I have ArrayList<Point> "big" to store all special ball but coordinat of the center only.

I hope this will make clear everything. On game class nothing special there.

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org