I’m tried to animate a PNG image using sample code that comes with the Nokia Development Suite(Helicopter). The PNG image I used consists of 7 frames of different actions the image will do. I understand the idea of the sample code to animate an image, I used my PNG image on it. It did animate but the problem is the animation is not what i expected, the frames seems to overlap each other. Can anyone suggest another sample code for animation and can you direct me to a resource about threading in J2ME? I also want to create a custom UI for a game I’m trying to do.
They probably are a different size from the helicopter images.
That’s not exactly a question.
shmoove
The images are of the sames size, the difference is that my image is a robot.
yah, your right its not a question, i’ll just edit it…thanks
Hi!
Seems that your code did not cleared the previous frame area, thus the operlapping of them all.
If you show your animation code will be more easy.
Also you can check this animation code: http://www.jtgl.org/modules/mylinks/visit.php?cid=12&lid=14
like in my initial post, I am modified the Helicopter sample code that comes with nokia development suite. I just removed the lines that would draw the background. That leaves me with the helicopter itself then i changed the image that was called and just increased the number of frames.
Here is the whole robot class.
[i]import javax.microedition.lcdui.;
import java.io.;
public class Robot
{
private static Image[] myImage;
private static int x, y;
private static int frame=4;
private static int imageWidth, imageHeight;
private final String CHARACTER_NAME=“proto01”;
private final String imgFiller="/filler.png";
private Image imgFill;
private Image[] imgCharacterStrip;
private final int CHARACTER_FRAMES=14;
private Image[] imgCharacter=new Image[CHARACTER_FRAMES];
private int clipAreas[][];
public Robot()
{
// load the images from the .jar
imgCharacterStrip=getImages(CHARACTER_NAME,1);
try {
imgFill = Image.createImage(imgFiller);
}
catch (IOException ex) {
}
// all character frame images are assumed
// to be the same height and width
imageWidth=imgCharacterStrip[0].getWidth()/CHARACTER_FRAMES;
imageHeight=imgCharacterStrip[0].getHeight();
// set the intial position of the character.
x=(Try1Canvas.getCanvasWidth()/2)-(imageWidth/2);
y=(Try1Canvas.getCanvasHeight()/2)-(imageHeight/2);
}
public void setFrame()
{
if(++frame>=CHARACTER_FRAMES)
{
frame=7;
}
}
public void draw(Graphics g)
{
if(imgCharacterStrip[0]!=null)
{
g.setClip(x,y,imageWidth,imageHeight);
//g.drawImage(imgFill,0,y,g.LEFT |g.TOP );
g.drawImage(imgCharacterStrip[0],x-(imageWidth*frame),y,g.LEFT | g.TOP);
//g.setClip(0,0,32,47);
g.setClip(0,0,Try1Canvas.getCanvasWidth(),Try1Canvas.getCanvasHeight());
}
}
public void draw2(Graphics g){
g.setClip(0,0,Try1Canvas.getCanvasWidth(),Try1Canvas.getCanvasHeight());
g.drawImage(imgFill,0,y,g.LEFT |g.TOP );
}
private Image[] getImages(String imgName, int frames)
{
return Try1.getImages(imgName, frames);
}
}[/i]
hope you can help a newbie …
You say you have 7 frames. So why is CHARACTER_FRAMES equal to 14. And in setFrame() you set the initial frame to 7?
Those are the things I find strange.
shmoove