| Reply | « Previous Thread | Next Thread » |
|
I'm developing an aplication that uses only one Image object to handle images and show it in the screen, my problem is that it loads the same image file every loop, how do I fix it? Here's a short example of the code:
Code:
int x = 0;
Image img;
while(end == false){
if(key == LEFT_PRESSED){
x--;
}
if(key == RIGHT_PRESSED){
x++;
}
switch(x){
case 1:
img = Image.createImage("/img01.png");
break;
case 2:
img = Image.createImage("/img02.png");
break;
case 3:
img = Image.createImage("/img03.png");
break;
case 4:
img = Image.createImage("/img04.png");
break;
//case 5 ...
//case 6 ...
//case 7 ...
}
graphic.drawImage(img, 0, 0, Graphics.LEFT | Graphics.TOP);
}
|
|
Hi,
You should do null of the image object on every event like that int x = 0; Image img; while(end == false){ if(key == LEFT_PRESSED){ x--; } if(key == RIGHT_PRESSED){ x++; } switch(x){ case 1: img=null; img = Image.createImage("/img01.png"); break; case 2: img=null; img = Image.createImage("/img02.png"); break; case 3: img=null; img = Image.createImage("/img03.png"); break; case 4: img=null; img = Image.createImage("/img04.png"); break; //case 5 ... //case 6 ... //case 7 ... } graphic.drawImage(img, 0, 0, Graphics.LEFT | Graphics.TOP); } |
| sharvan1981 |
| View Public Profile |
| Find all posts by sharvan1981 |
|
Quote:
Where is this code? It looks like it's from the run() method of a class than extends GameCanvas and implements Runnable, yes? In that case, you need to call flushGraphics(). No, you don't need to set the variable to null. Loading images can be time consuming on some devices... unless the images are very large, you might consider loading them (for example, into an Image[]) ahead of time. Cheers, Graham. |
| grahamhughes |
| View Public Profile |
| Find all posts by grahamhughes |
|
Quote:
Using the Image[] does not fit here, because I'll have so many images, and loading them all before may take a long time to load and cause an Out of Memory exception, thats because I want a "real time" loading. |
|
Once I have a problem with the method run and a parameter. A function call with a parameter inside a run method, every time the call was with the first value of the parameter, to get it "working" I've changed the parameter for a class atributte. Maybe this help you.
|
| fletcher.jonnes |
| View Public Profile |
| Find all posts by fletcher.jonnes |
|
Possible problems:
1. You aren't calling flushGraphics()... until you do this, nothing you draw will appear. 2. An exception is being thrown, and you're ignoring it. 3. "x" doesn't have the value you think it has. 4. You have two variables called "img", and one is hiding the other. When you do this: Code:
img = Image.createImage("/img02.png");
1. img will refer to a new Image object, representing the data in /img02.png; or 2. An exception is thrown, and img is unchanged. Nothing else can happen. Cheers, Graham. |
| grahamhughes |
| View Public Profile |
| Find all posts by grahamhughes |
| Reply | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|
| Thread | Thread Starter | Forum | Replies | Last Post |
|---|---|---|---|---|
| --- ???save image problem??? --- | ferenn | Mobile Java Media (Graphics & Sounds) | 6 | 2007-10-01 15:33 |
| Problem when creating Image !!! | cvraiden | Mobile Java Media (Graphics & Sounds) | 3 | 2007-07-10 17:33 |
| KERN-EXEC 0 when trying to access kernel object handle i.e. driver channel handle | jayanjohn | General Symbian C++ | 0 | 2006-12-26 13:35 |
| intercept/catch the image object | Rx- | Bluetooth Technology | 0 | 2004-02-18 07:25 |
| Get pixel data from an image object on Nokia phones? | inopia | Mobile Java General | 1 | 2002-05-15 10:27 |