paco_rjp
Junior Newbie
Java games rock!
|
 |
«
Reply #4 - Posted
2004-04-22 01:07:27 » |
|
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.
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); } }
hope you can help a newbie ...
|