我正在用andengine开发一款游戏。我有玩家。还有随机时间与MoveModifier一起出现的敌人,他们是精灵。我想:玩家射击子弹,子弹接触敌人,敌人将是看不见。我该怎么办?
子弹
private Runnable mStartCircle1 = new Runnable() {
public void run() {
final Scene scene= HelicopterActivity.this.mEngine.getScene();
float velocityOfCircleC=1.6f;
float startXC=player.getX()+50;
float finishXC=800;
float startYC=player.getY()+15;
float finishYC=startYC;
bullet=new Sprite(startXC, startYC, HelicopterActivity.this.gasTextureRegion);
bullet.registerEntityModifier(
(IEntityModifier) new SequenceEntityModifier (
new MoveModifier(velocityOfCircleC, bullet.getX(), finishXC, bullet.getY(), finishYC)));
scene.attachChild(bullet);
敌人
int j=0, k=0;
private Runnable mStartCircle = new Runnable() {
public void run() {
final Scene scene= HelicopterActivity.this.mEngine.getScene();
float startY=randomNumber.nextInt(670 - 1);
float velocityOfCircle=6;
enemy[j] = new Sprite( 800, startY, HelicopterActivity.this.enemyTextureRegion);
enemy[j].registerEntityModifier(
(IEntityModifier) new SequenceEntityModifier (
new MoveModifier(velocityOfCircle, enemy[j].getX(), -128,
enemy[j].getY(), enemy[j].getY())));
scene.attachChild(enemy[j]);
float startY2=randomNumber.nextInt(670 - 1);
float velocityOfCircle2=10;
enemy2[k] = new Sprite( 800, startY2, HelicopterActivity.this.enemy2TextureRegion);
enemy2[k].registerEntityModifier(
(IEntityModifier) new SequenceEntityModifier (
new MoveModifier(velocityOfCircle2, enemy2[k].getX(), -128,
enemy2[k].getY(), enemy2[k].getY())));
scene.attachChild(enemy2[k]);
k++;
j++;
if (k<50){
mHandler.postDelayed(mStartCircle,5000);
}
}};
if (i<1000){
mHandler.postDelayed(mStartCircle1,1000);
}
}};
答案 0 :(得分:2)
这是与你类似的游戏......在这些例子中是碰撞检测示例:
答案 1 :(得分:1)