📄 roleaction.java
字号:
import javax.microedition.lcdui.*;
import java.io.*;
public class RoleAction {
private byte m_FrameNum;//一个动作有几帧
private ActionFrame[] m_ActionFrame;
private int actionID;//当前要绘制的帧ID
public RoleAction() {
}
public void copyAction(){
}
/**
* 拷贝动作类
* @param rA RoleAction
*/
public void copyAction(RoleAction rA) {
m_FrameNum = rA.m_FrameNum;//复制帧数
m_ActionFrame = new ActionFrame[m_FrameNum];//创建帧数组
for (int i = 0; i < m_FrameNum; i++) {
m_ActionFrame[i] = new ActionFrame();//创建帧
m_ActionFrame[i].copyFrame(rA.m_ActionFrame[i]);//复制帧
}
}
/**
* 载入动作数据
* @param din DataInputStream
*/
public void loadActionData(DataInputStream din){
try {
m_FrameNum = din.readByte(); //取得该动作的帧数
m_ActionFrame = new ActionFrame[m_FrameNum];//建帧数组
for (int i = 0; i < m_FrameNum; i++) {
m_ActionFrame[i] = new ActionFrame();//建帧对象
m_ActionFrame[i].loadFrameData(din); //调用ActionFrame的载数据函数来获得每帧数据
}
}
catch (IOException ex) {
ex.printStackTrace();
}
}
/**
* 绘制动作的帧
* @param g Graphics
* @param x int 要绘制到的屏幕坐标
* @param y int
*/
public boolean drawRoleAction(Graphics g,int x,int y,int type,int actionType){
if (actionType == 1) {//只播放第1帧
m_ActionFrame[0].drawActionFrame(g, x, y, type);
}else {
if (m_ActionFrame[actionID].drawActionFrame(g, x, y, type)) { //如果绘制帧的时间到了
actionID++; //切换到下一帧
if (actionID >= m_FrameNum) { //如果超出帧范围了
actionID = 0; //又从第1帧开始
if(actionType == 0){//只播放一次动作 否则循环播放
return true;//播放完了一个动作
}
}
}
}
return false;
}
public int[] getHitRect() { //取得当前帧的碰撞区域
return m_ActionFrame[actionID].getM_iHitRect();
}
public int[] getAttackRect() { //取得当前帧的攻击区域
return m_ActionFrame[actionID].getM_iAttackRect();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -