Solved

Java3D: how to load and change textures quickly

Posted on 2004-09-06
8
343 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
copyEndy  challenge 15 55
parentbit challenge 3 52
Passing list of object to Oracle Database Procedure 3 41
eclipse formatting 6 40
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

708 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

16 Experts available now in Live!

Get 1:1 Help Now