Java awt performance anxiety -
there program generates hundreds or thousands of moving particles onscreen @ once. after several hundred displayed, slowdown occurs. performance analyzed using netbeans profiler , 80% of time spend in jpanel's paint method...so algorithm optimization seems unlikely make noticeable difference. there can done or time think new platform? paint method looks this:
public void paintcomponent(graphics g) { super.paintcomponent(g); setbackground(color.white); (int = 0; < gamelogic.getparticlearrsize(); i++) { g.setcolor(gamelogic.getparticlecolor(i)); g.filloval(gamelogic.getparticlexcoor(i), gamelogic.getparticleycoor(i), gamelogic.getparticlesize(i), gamelogic.getparticlesize(i)); } g.setcolor(gamelogic.getcurrpartcolor()); g.filloval(mousex - mouseovalradius, mousey - mouseovalradius, mouseovalsize, mouseovalsize); g.setcolor(gamelogic.getcursorcolor()); g.filloval(mousex - 19, mousey - 19, 38, 38); (int = 0; < gamelogic.getbombarrsize(); i++) { g.setcolor(color.red); g.filloval(gamelogic.getbombxcoor(i) - 6, gamelogic.getbombycoor(i) - 6, gamelogic.getbombsize(i), gamelogic.getbombsize(i)); } (int = 0; < gamelogic.getpowerupparticlearrsize(); i++) { g.setcolor(gamelogic.getpowerupparticlecolor(i)); g.filloval(gamelogic.getpowerupparticlexcoor(i), gamelogic.getpowerupparticleycoor(i), gamelogic.getpowerupparticlesize(i), gamelogic.getpowerupparticlesize(i)); } (int = 0; < gamelogic.getblackarrsize(); i++) { g.setcolor(color.black); g.filloval(gamelogic.getblackparticlexcoor(i), gamelogic.getblackparticleycoor(i), gamelogic.getblackparticlesize(i), gamelogic.getblackparticlesize(i)); } }
when triggering repaint()? set on timer on time interval? created animation lib , able animate 40 items smoothly. have many more objects @ time interval first.
edit: ok here suggestion. first need figure out function in paint taking amount of time. seems calling filloval lot. suggestion create shape once using like: new roundrectangle2d.double(). , use affinetransformation move around shapes instead. curious know other suggest, check back.
Comments
Post a Comment