本想实现动画制作(一张大图上很多张小图片不停地切换)却什么也显示不了
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.GameCanvas;
import javax.microedition.lcdui.game.Sprite;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
//制作旋转动画
public class xz extends MIDlet {
private Display dis;
private Mygamecanvas mgc=new Mygamecanvas();
protected void startApp() throws MIDletStateChangeException {
dis=Display.getDisplay(this);
dis.setCurrent(mgc);
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
}
protected void pauseApp() {
}
//我的游戏画布
class Mygamecanvas extends GameCanvas implements Runnable{
private boolean run=true;
private Image img;
private Sprite sp1;
private Graphics g;
protected Mygamecanvas() {
super(true);
try{
img=Image.createImage("/xz.png");
sp1=new Sprite(img,img.getWidth()/3,img.getHeight()/3);
g=this.getGraphics();
}catch(Exception ex)
{
ex.printStackTrace();
}
new Thread(this).start();
}
public void run() {
while(run)
{
sp1.paint(g);
this.flushGraphics();
sp1.nextFrame();
try{
Thread.currentThread().sleep(100);
}catch(Exception ex)
{
}
}
}
}
}
------解决方案--------------------帧序列没有设置,先设置帧序列setFrameSequence
还有异常信息最好打印出来,这样容易看出问题
------解决方案--------------------请给出异常栈
------解决方案--------------------没有 setPosition
Java code
sp1.setPosition(x,y);