📄 mymovingobject.java
字号:
package example;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2003</p> * <p>Company: Sensible Development Ltd</p> * @author Alan Newman * @version 1.0 */import javax.microedition.lcdui.*;import java.util.Random;public class MyMovingObject{ private static Image[] myImage; private static int x, y; private static int direction=1; private static int frame=0; private static int imageWidth, imageHeight; private final String CHARACTER_NAME="helicopter_strip"; private Image[] imgCharacterStrip; private final int CHARACTER_FRAMES=3; private Image[] imgCharacter=new Image[CHARACTER_FRAMES]; private int clipAreas[][]; public MyMovingObject() { // load the images from the .jar imgCharacterStrip=getImages(CHARACTER_NAME,1); // 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=(MyCanvas.getCanvasWidth()/2)-(imageWidth/2); y=(MyCanvas.getCanvasHeight()/2)-(imageHeight/2); } public void setFrame() { if(++frame>=CHARACTER_FRAMES) { frame=0; } } public void draw(Graphics g) { if(imgCharacterStrip[0]!=null) { g.setClip(x,y,imageWidth,imageHeight); g.drawImage(imgCharacterStrip[0],x-(imageWidth*frame),y,g.LEFT | g.TOP); g.setClip(0,0,MyCanvas.getCanvasWidth(),MyCanvas.getCanvasHeight()); } } private Image[] getImages(String imgName, int frames) { return ExampleMidlet.getImages(imgName, frames); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -