Link to home
Start Free TrialLog in
Avatar of yomeng
yomeng

asked on

Java3D: how to load and change textures quickly

At the moment, I am animating a character using sprites and...

- if I load the sprite jus when I need it, I get delays (probably becoz of the time taken to load the image onto memory. And maybe if you could explain why a 10+kb png graphics will take so much time and memory space)

- if I load all sprites onto memory 1st, I find that i consume too much memory (like 10+mb for 1 character. I use 128x128 png images becoz i need gd transparency support). Thus, it is not a viable solution in the long run when i implement more characters and result in outofmemory.

Qn1a: So I ask if there is anyway to speed up the loading and changing of textures (like an animation).

Qn1b: I also ask on how sprite based games (that has everchanging sprites) reduce their memory usage.

below is how i load a texture. Please let me know if there is a better way. Thanks.


-----------------------------------------------
     TextureLoader textureLoader = new TextureLoader("filename.png", null);
     ImageComponent2D image = textureLoader.getImage();
     Texture2D texture = new Texture2D(Texture2D.BASE_LEVEL, Texture.RGBA,
                                         image.getWidth(), image.getHeight());
     texture.setImage(0, image);
     texture.setEnable(true);
----------------------------------------------
ASKER CERTIFIED SOLUTION
Avatar of girionis
girionis
Flag of Greece image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of yomeng
yomeng

ASKER

could you care to elaborate on your solution? But i'm afraid that i might NOT know wat image to load until the user interacts with the scene.

for example, if the user clicks right, i need the east walking sprites. And if the clicks left, vice versa.
You could have a mouse listener that listens for mouse clicks events. If the mouse event is a right click then spawn two threads from the corresponding method. In there have one thread reading the images and have the other thread display them to the user while they are being read. The threads should terminate after the images are all loaded and they are displayed on the screen.
Avatar of yomeng

ASKER

would this sort of have a high chance of working? cause it will make quite a number of changes to my program.
Avatar of yomeng

ASKER

to add on, how do i inform the thread-that-does-the-showing that the thread-that-does-the-loading has finish loading?

if i run a while loop, i probably need to put a sleep/delay but putting too long a delay would result in delayed showing of the image.
You will run a while loop, when it is finished then the run method will exit (and the thread will die).

> if i run a while loop, i probably need to put a sleep/delay but putting too long a delay would result in delayed showing of the image.

You can put a delay of 20ms or even less.

Before you make any changes to your original programme though I suggest you write a small sampel application that does this and see how it is going.
My opinion is that I have already answered the question.