[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Java3D: how to load and change textures quickly

Posted on 2004-09-06
8
Medium Priority
?
373 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
7 Comments
 
LVL 35

Accepted Solution

by:
girionis earned 500 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses
Course of the Month19 days, 22 hours left to enroll

873 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