Solved

Java3D: how to load and change textures quickly

Posted on 2004-09-06
8
345 Views
Last Modified: 2008-03-10
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);
----------------------------------------------
0
Comment
Question by:yomeng
  • 4
  • 3
8 Comments
 
LVL 35

Accepted Solution

by:
girionis earned 250 total points
ID: 11989679
Have you tried using threads? Load images on demand and show them while you are loading them? Have a different thread to load images and a different one to show them.
0
 

Author Comment

by:yomeng
ID: 11989716
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.
0
 
LVL 35

Expert Comment

by:girionis
ID: 11989750
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.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:yomeng
ID: 11989795
would this sort of have a high chance of working? cause it will make quite a number of changes to my program.
0
 

Author Comment

by:yomeng
ID: 11990010
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.
0
 
LVL 35

Expert Comment

by:girionis
ID: 11990252
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.
0
 
LVL 35

Expert Comment

by:girionis
ID: 12215235
My opinion is that I have already answered the question.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now