Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/381.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
Pluralsight使用Java为Android和PC构建第一款游戏_Java_Android Studio_Libgdx - Fatal编程技术网

Pluralsight使用Java为Android和PC构建第一款游戏

Pluralsight使用Java为Android和PC构建第一款游戏,java,android-studio,libgdx,Java,Android Studio,Libgdx,我正在处理这个问题,遵循所有步骤,但出现了错误。问题是 public boolean playerShotTouches(Rectangle boundingBox) { Iterator<AnimatedSprite> i = shots.iterator(); while(i.hasNext()) { AnimatedSprite shot = i.next(); if(Intersector.intersectRecta

我正在处理这个问题,遵循所有步骤,但出现了错误。问题是

 public boolean playerShotTouches(Rectangle boundingBox) {
    Iterator<AnimatedSprite> i = shots.iterator();
    while(i.hasNext())
    {
        AnimatedSprite shot = i.next();
        if(Intersector.intersectRectangles(shot.getBoundingBox(), boundingBox))
        {
            i.remove();
            return true;
        }
    }
    return false;
}
public boolean播放器触摸屏(矩形边框){
迭代器i=shots.Iterator();
while(i.hasNext())
{
AnimatedSprite shot=i.next();
if(Intersector.intersect矩形(shot.getBoundingBox(),boundingBox))
{
i、 删除();
返回true;
}
}
返回false;
}
android studio报告:

错误:(108,27)错误:类Intersector中的方法Intersect矩形不能应用于给定类型; 必需:矩形,矩形,矩形 找到:矩形,矩形 原因:实际参数列表和正式参数列表长度不同


你能发布课程中的相关代码吗?相交矩形方法始终采用3个矩形作为参数。第三个是重叠区域的相交矩形。因此,您的代码可以执行如下操作:

AnimatedSprite shot = i.next();
Rectangle myIntersection = new Rectangle();
if(Intersector.intersectRectangles(shot.getBoundingBox(), boundingBox, myIntersection))

你能发布课程中的相关代码吗?相交矩形方法始终采用3个矩形作为参数。第三个是重叠区域的相交矩形。因此,您的代码可以执行如下操作:

AnimatedSprite shot = i.next();
Rectangle myIntersection = new Rectangle();
if(Intersector.intersectRectangles(shot.getBoundingBox(), boundingBox, myIntersection))

错误消息表示该方法需要三个矩形作为参数,但您只传递了两个矩形(
shot.getBoundingBox()
boundingBox
)。Jesper,谢谢您的时间。这很清楚,没有中间点声明(来自错误报告),但在课程视频中,他只声明了这两个,并且游戏运行良好(只是在最后代码中勾选了,它们只有两个偏差。你能告诉我如何声明中间点(第三个矩形)?错误消息表示方法
intersectRectangles
需要三个矩形作为参数,但您只传递了两个矩形(
shot.getBoundingBox()
boundingBox
)。Jesper,谢谢您的时间。很清楚,没有intersection声明(来自错误报告)但在课程视频中,他只声明了这两个,游戏运行良好(只是在curs最终代码中勾选了,它们只有2个偏差。你能告诉我如何声明interspection(第三个矩形)吗?谢谢Peter,第三个矩形游戏运行良好。这是课程代码:
public boolean PlayerShorthotches(矩形边框){返回ShortTouchs(镜头,边框);}
公共布尔镜头镜头(矩形边框){返回镜头镜头(镜头,边框);}私有布尔镜头镜头(列表镜头,矩形边框){Iterator i=shots.Iterator();而(i.hasNext()){AnimatedSprite shot=i.next();if(Intersector.intersectorrectangles(shot.getBoundingBox(),boundingBox)){i.remove();返回true;}}}返回false;}
我复制了最后一个代码,但仍然不起作用,但当我添加第三个矩形时,我的Intersection可以正常工作。如果你有时间检查课程代码,告诉我是错误的还是我做了一些坏事。因为他们的代码正常工作,我不知道该告诉你什么。libgdx IntersectRectanges方法需要3个矩形参数。可能是因为se正在使用库的修改版本(我觉得这很奇怪)。在示例代码中,您实际上没有使用第三个矩形的值,因此您不需要显式创建myIntersection变量,这也会起作用:if(Intersector.intersectRectangles(shot.getBoundingBox(),boundingBox,new rectangle())谢谢Peter,第三个矩形游戏可以使用。这是课程代码:
public boolean playerShotTouches(矩形边框){return shottooks(shots,boundingBox);}
public boolean enemyshottooks(矩形边框){return shottooks(enemyShots,boundingBox);}private boolean shottools(列出快照,矩形边框){Iterator i=shots.Iterator();而(i.hasNext()){AnimatedSprite shot=i.next();if(Intersector.intersect矩形(shot.getBoundingBox(),boundingBox)){i.remove();返回true;}返回false;}
我复制了最后一个代码,但仍然不起作用,但当我添加第三个矩形时,我的Intersection可以正常工作。如果你有时间检查课程代码,告诉我是错误的还是我做了一些坏事。因为他们的代码正常工作,我不知道该告诉你什么。libgdx IntersectRectanges方法需要3个矩形参数。可能是因为se正在使用库的修改版本(我觉得这很奇怪)。在示例代码中,您实际上没有使用第三个矩形的值,因此您不需要显式创建myIntersection变量,这也会起作用:if(Intersector.intersectRectangles(shot.getBoundingBox(),boundingBox,new rectangle())