?? background.java
字號:
/**
*游戲精靈類
*@CopyRight:Move2008
*@Author:bedlang
*@Version 1.0 2003/10/13
*/
package mmae.game;
import javax.microedition.lcdui.*;
public class BackGround extends mmae.ui.Base
{
public static final int UP = 0;
public static final int DOWN = 1;
public static final int LEFT = 2;
public static final int RIGHT = 3;
public int offSetV,offSetH;
private Image[] imgArray;
private int way;
private int oldWay;
private boolean is360D;
private int imgWidth,imgHeight;
public int step=1;
private boolean auto = true;
public BackGround(Image[] images, int Left, int Top, int Width, int Height)
{
setRect(Left,Top,Width,Height);
imgArray = images;
for(int i=0;i<imgArray.length;i++)
imgWidth += imgArray[i].getWidth();
imgHeight = imgArray[0].getHeight();
offSetH = offSetV = 0;
is360D = true;
way = oldWay = RIGHT;
}
public boolean isAuto()
{
return auto;
}
public void setAuto(boolean Auto)
{
auto = Auto;
}
public void set360(boolean Is360)
{
is360D = Is360;
}
public boolean is360()
{
return is360D;
}
public void setStep(int i)
{
if(i>=0) step = i;
}
public int getStep()
{
return step;
}
public void setWay(int Way)
{
if (way==2 || way==3) oldWay=way;
way = Way;
}
public int getWay()
{
return way;
}
public void move()
{
switch(way)
{
case UP://UP
if( offSetH<0 )
offSetH+=step;
else
if(oldWay==2 || oldWay==3)
setWay(oldWay);
break;
case DOWN://DOWN
if( offSetH-step>=height-imgHeight )
offSetH-=step;
else
if(oldWay==2 || oldWay==3)
setWay(oldWay);
break;
case LEFT://LEFT
if(is360D)
{
offSetV-=step;
if( offSetV<(width-imgWidth) ) offSetV=width;
}
else
if( offSetV-step>width-imgWidth ) offSetV-=step;
break;
case RIGHT://RIGHT
if(is360D)
{
offSetV+=step;
if( offSetV>imgWidth) offSetV=0;
}
else
if( offSetV+step<0 ) offSetV+=step;
break;
}
}
public void draw(Graphics g)
{
int i1 = g.getClipX();
int j1 = g.getClipY();
int k1 = g.getClipWidth();
int l1 = g.getClipHeight();
g.setClip(left,top,width,height);
for(int i=0;i<=width/imgWidth+1;i++)
{
for(int t=0;t<=height/imgHeight+1;t++)
{
int w=0;
for(int j=0;j<imgArray.length;j++)
{
g.drawImage(imgArray[j],offSetV-i*imgWidth+left+w,offSetH+top+t*imgHeight,g.TOP|g.LEFT);
w += imgArray[j].getWidth();
}
}
}
g.setClip(i1,j1,k1,l1);
}
public int getWidth()
{
return imgWidth;
}
public int getHeight()
{
return imgHeight;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -