Solved

Java3D: how to load and change textures quickly

Posted on 2004-09-06
8
358 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 

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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Configure a Bean in an XML file 4 49
Bot application - advice 3 64
Running JavaFX on the Raspberry Pi 27 155
Java array 21 88
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
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…

696 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