getRefPixelX()指的是什么
我在一款飞机射击类游戏中看到,导弹的获得坐标是int nX = getRefPixelX() + m_nSpeedX;请问getRefPixelX()指的是什么,谢谢。
------解决方案--------------------
import java.util.Random;
import javax.microedition.lcdui.Image;
public class EnemyPlane extends PlaneSprite{
private Random m_Random;
EnemyPlane( Image img, int nWidth, int nHeight ){
super( img, nWidth, nHeight );
m_Random = new Random();
}
//逻辑操作
public void Logic( int scrWidth, int scrHeight ){
super.Logic(scrWidth, scrHeight);
if( isVisible() == false )
return;
int nX = getRefPixelX() + m_nSpeedX;
int nY = getRefPixelY() + m_nSpeedY;
setRefPixelPosition( nX, nY );
if( getRefPixelX() < -getWidth() ||
getRefPixelX() > scrWidth + getWidth() ||
getRefPixelY() < -getHeight()||
getRefPixelY() > scrHeight + getHeight() )
setVisible(false);
CreateMissile();
}
//发射炮弹
private void CreateMissile(){
//如果已经发射了炮弹,则暂时不能发射
if( m_Missile.isVisible() )
return;
int RS = Math.abs(m_Random.nextInt() % 30 );
if( RS != 0 )
return;
int nSpeedX = m_Random.nextInt() % 2;
int nSpeedY = Math.abs(m_Random.nextInt() % 2 ) + 1;
m_Missile.SetSpeed( nSpeedX, nSpeedY );
m_Missile.setRefPixelPosition(
getRefPixelX(), getRefPixelY() );
m_Missile.setVisible(true);
}
}
//package demo;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.Sprite;
public class MissileSprite extends Sprite{
private int m_nSpeedX = 0; //导弹X方向的移动速率
private int m_nSpeedY = 0; //导弹Y方向的移动速率
MissileSprite(Image image, int frameWidth, int frameHeight){
super( image, frameWidth, frameHeight );
defineReferencePixel( frameWidth / 2, frameHeight / 2 );
setVisible(false);
}
//设置移动速率,注意速率与速度的差别
public void SetSpeed( int nSpeedX, int nSpeedY ){
m_nSpeedX = nSpeedX;
m_nSpeedY = nSpeedY;
}
//逻辑操作,参数scrWidth、scrHeight分别是屏幕的宽和高
public void Logic( int scrWidth, int scrHeight ){
if( isVisible() == false )
return;
int nX = getRefPixelX() + m_nSpeedX;
int nY = getRefPixelY() + m_nSpeedY;
setRefPixelPosition( nX, nY );
if( getRefPixelX() < -getWidth() ||
getRefPixelX() > scrWidth + getWidth()||
getRefPixelY() < -getHeight() ||
getRefPixelY() > scrHeight + getHeight() )
setVisible(false);
}
}
//package demo;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.Sprite;
public class ExplosionSprite extends Sprite{
ExplosionSprite(Image image, int frameWidth, int frameHeight) {
super(image, frameWidth, frameHeight);
defineReferencePixel( frameWidth / 2, frameHeight / 2 );
setVisible( false );
}
//开起爆炸
//参数nX、nY分别是爆炸位置的横纵坐标
public void Start( int nX, int nY ){
setRefPixelPosition( nX, nY );
setVisible(true);
setFrame(0);
}
//逻辑操作,产生爆炸动画
public void Logic(){
if( !isVisible() )
return;
int nFrame = getFrame();
nFrame ++;
if( nFrame >= getFrameSequenceLength() ){
setVisible( false );
return;
}
setFrame( nFrame );
}
}