📄 gif.java
字号:
package code;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.Graphics;
public class Gif
{
public String name = "gif";
public int life = 1;
public int pos_x = 0;
public int pos_y = 0;
public int w = 10;
public int h = 10;
public int form = 1;
private int allTime;
private int currForm;
private long startTime;
public boolean isShow=true;
public int[] formTime={100};
private Image[] img;
public Gif( String _name, int _form, int _w, int _h )
{
w = _w;
h = _h;
setGif( _name, _form );
startTime = System.currentTimeMillis();
setPos();
}
public void setGif( String _name, int _form )
{
try
{
name = _name;
form = _form;
formTime= new int[form];
img = new Image[form];
for( int i=0; i<form; i++ )
{
formTime[i] = 100;
allTime += formTime[i];
img[i] = Image.createImage("/pics/"+name+"_"+i+".png");
}
// Image temp = Image.createImage("/pics/"+name+".png");
// form = temp.getWidth()/w;
// formTime = new int[form];
// img = new Image[form];
// Graphics gn;
// for( int i=0; i<img.length; i++ )
// {
// formTime[i] = 100;
// allTime +=formTime[i];
// img[i] = Image.createImage(w, h);
// gn = img[i].getGraphics();
// gn.drawImage(temp, -i*w, 0, gn.LEFT|gn.TOP);
// }
// gn = null;
// temp = null;
// System.gc();
}catch(Exception e){ e.printStackTrace(); }
}
public void setPos()
{
pos_x = cGame.rand.nextInt(cGame.s_width-w) + ( w>>1 );
pos_y = cGame.rand.nextInt(cGame.s_height-h) + ( h>>1 );
startTime = System.currentTimeMillis();
}
public void setFormTime(int[] _formTime)
{
formTime = _formTime;
allTime = 0;
for( int i=0; i<formTime.length; i++ )
{
allTime +=formTime[i];
}
startTime = System.currentTimeMillis();
}
public void paint(Graphics g)
{
if( isShow )
{
long now = System.currentTimeMillis();
long time= (now-startTime)%allTime;
for(int i=0; i<form; i++)
{
time -= formTime[i];
if( time<=0 )
{
g.drawImage(img[i], pos_x, pos_y, g.HCENTER|g.VCENTER);
break;
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -