Performance problems with animation technique

T

Tristan

Hi,

I have some performance problems with the following animation
technique:
- I have one container like JPanel
- I have sprites that are threads and have a reference to the
container
- the sprites change their state *very* often (but not endless loop)
and call their container to repaint each time the state changes
- the container itself then calls paintComponent and paints all the
sprites that it knows

Now the problem with that technique is that, if I have too many
sprites (threads) the performance gets worse for each sprite, because
the calls to the container increase too much.
Is there any other technique ? How does a layer technique work ?

Thanks.

Cu, Tristan.
 
J

J.P.Jarolim

Hi.

You should consider to use another perspective:
Your animation should have a specified refresh rate to appear smooth.
So you should specify that refresh-rate (eg. 25 images/second).

On the other side you have a stack of graphical objects which change their
state very often.
All you have to do is to look into that stack just 25 times a second (no
matter the state of the single objects).

Decouple the two things (drawing the image and updating the objects) by
creating two threads.
The updating thread can run faster than the drawing thread, but you (or your
user) can't see more than 25 images / second.

just my thoughts,

J.P.Jarolim
 
A

Anonymous

Tristan said:
Hi,

I have some performance problems with the following animation
technique:
- I have one container like JPanel
- I have sprites that are threads and have a reference to the
container
- the sprites change their state *very* often (but not endless loop)
and call their container to repaint each time the state changes
- the container itself then calls paintComponent and paints all the
sprites that it knows

Now the problem with that technique is that, if I have too many
sprites (threads) the performance gets worse for each sprite, because
the calls to the container increase too much.
Is there any other technique ? How does a layer technique work ?

The problem is that paint takes much longer than the sprite changes
so requests to paint pile up. Why not provide some check to prevent
paintComponent being called so frequently.
 
R

Roedy Green

- the sprites change their state *very* often

Look into VolatileImage so that the various sprite configurations are
pre-drawn and already in the REGEN buffer.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,831
Latest member
HealthSmartketoReviews

Latest Threads

Top