⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 goodssprite.java

📁 J2ME手机游戏50例
💻 JAVA
字号:
package demo;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.Sprite;


public class GoodsSprite extends Sprite{
	//定义一组表示物品类型的数值
	public static final int GODDS_GOLD 		= 0;	//金元宝
	public static final int GODDS_DIAMOND 	= 1;	//钻石
	public static final int GODDS_FRUIT 		= 2;	//水果
	public static final int GODDS_TYPE_NUM 	= 3;	//类型总数
	private int m_nType = GODDS_GOLD;
	public GoodsSprite( Image image, int frameWidth, int frameHeight){
		super(image, frameWidth, frameHeight);		
		defineReferencePixel(frameWidth / 2, frameHeight / 2);		
		setVisible( false ); 				//刚产生时,并不可见
	}
	//获得物品的类型
	public int getType(){
		return m_nType;
	}
	//设置物品的类型
	public void setType( int type ){
		m_nType = type;
		if( m_nType < 0 || m_nType >= GODDS_TYPE_NUM )
			m_nType = GODDS_GOLD;
		setFrame(m_nType);
	}
	//让物品开始掉落,参数x与y分别是物品起始点的位置
	public void StartDrop( int x, int y ){
		setRefPixelPosition( x, y );
		setVisible( true );
	}
	//逻辑操作,产生并管理物品下落的动画
	public void Logic( int srcHeight ){
		if( isVisible() == false )
			return;
		int y = getRefPixelY();
		y = y + 5;
		setRefPixelPosition( getRefPixelX(), y );
		if( y >= srcHeight )
			setVisible( false );
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -