Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java LibGDX onTouch()方法数组和flip方法_Java_Android_Arrays_Libgdx_Ontouch - Fatal编程技术网

Java LibGDX onTouch()方法数组和flip方法

Java LibGDX onTouch()方法数组和flip方法,java,android,arrays,libgdx,ontouch,Java,Android,Arrays,Libgdx,Ontouch,如何在我的应用程序中添加此项。 我想使用InputProcessor实现中的onTouch()方法来杀死屏幕上的敌人。 我该怎么做? 我必须对敌人阶级做些什么吗? 另外,我正在尝试添加一个敌人数组,它不断抛出异常,或者子弹现在朝向左侧添加到敌人类中,该类函数将返回一个边界矩形 public Rectangle getBounds() { return new Rectangle(xPosition,yPosition,width,height); } 现在,在你的screen类或你想去的地方,

如何在我的应用程序中添加此项。 我想使用InputProcessor实现中的onTouch()方法来杀死屏幕上的敌人。 我该怎么做? 我必须对敌人阶级做些什么吗?
另外,我正在尝试添加一个敌人数组,它不断抛出异常,或者子弹现在朝向左侧添加到敌人类中,该类函数将返回一个边界矩形

public Rectangle getBounds()
{
return new Rectangle(xPosition,yPosition,width,height);
}
现在,在你的screen类或你想去的地方,制造一个敌人数组或该类的名称

Array<Enemy> enemies =new Array<Enemy>();
在接地方法中,检查每个人是否被触碰

    @Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
for(int i=0; i<enemies.size; i++)
     if(enemies.get(i).getBounds().contains(screenX,screenY))
         enemies.removeIndex(i--); // if we touch an enemy remove it, we use i-- because we want to go back one, so we won't get the out of range exception if the last element in the array is touched!

 return false;
}
在gamerenderer类中,只需创建“Bullet”数组

Array<Bullet> enemies=new Array<Bullet>(); // that's it!
现在在你的名单上

要渲染每个项目符号,请在渲染方法中使用此选项

    for(int i=0; i<enemies.size; i++)
       enemies.get(i).draw(batch);

for(int i=0;我已经告诉过你了!再看看。你能给我看看你的敌人类吗?粘贴并在这里发布链接,如果我帮了忙,也别忘了接受我的回答!我添加了敌人类谢谢你Paul会尝试的,我会确保我表示感谢的,伙计。我已经添加了所有的类。我已经告诉你需要做什么。
public Rectangle getBounds()
{
return new Rectangle(xPosition,yPosition,width,height);
}
Array<Enemy> enemies =new Array<Enemy>();
enemies.add(new Enemy(.......));
    @Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
for(int i=0; i<enemies.size; i++)
     if(enemies.get(i).getBounds().contains(screenX,screenY))
         enemies.removeIndex(i--); // if we touch an enemy remove it, we use i-- because we want to go back one, so we won't get the out of range exception if the last element in the array is touched!

 return false;
}
public Rectangle getBounds()
{
return this.getBoundingRectangle();
}
Array<Bullet> enemies=new Array<Bullet>(); // that's it!
enemies.add(new Bullet(x,y));
    for(int i=0; i<enemies.size; i++)
       enemies.get(i).draw(batch);
 for(int i=0; i<enemies.size; i++)
    enemies.get(i).update(delta);