Java 矩形和圆之间的LibGDX交点

Java 矩形和圆之间的LibGDX交点,java,libgdx,collision-detection,intersection,Java,Libgdx,Collision Detection,Intersection,在我的自上而下游戏中,我使用加速计移动我的角色,现在我正在研究矩形和圆形猫和球之间的碰撞检测,但我的代码不起作用。我希望猫在击球时停止,并且在我左右移动手机时再次设置动画。猫是我的玩家,球是我的障碍 这是我的密码 // Load the sprite sheet as a texture cat = new Texture(Gdx.files.internal("cat.png")); catsprite = new Sprite(cat); player = new R

在我的自上而下游戏中,我使用
加速计
移动我的角色,现在我正在研究矩形和圆形猫和球之间的碰撞检测,但我的代码不起作用。我希望猫在击球时停止,并且在我左右移动手机时再次设置动画。猫是我的玩家,球是我的障碍

这是我的密码

// Load the sprite sheet as a texture
    cat = new Texture(Gdx.files.internal("cat.png"));
    catsprite = new Sprite(cat);
    player = new Rectangle();
    player.width = 20;
    player.height = 80;
    playerX = 300;
    playerY = 0;

    basketball = new Texture(Gdx.files.internal("equip/Basketball.png"));
    ball = new Circle();
    ball.x = Gdx.graphics.getWidth() / 2;
    ball.y = Gdx.graphics.getHeight() / 2;
    ball.radius = basketball.getWidth() / 2;
在渲染方法中

spriteBatch.draw(basketball, ball.x-ball.radius, ball.y-ball.radius);
spriteBatch.draw(currentFrame,playerX, playerY);// Draw current frame at (50, 50)  

    if(playerY < 0) playerY = 0;
    if(playerY > 700 - 80) playerY = 700 - 80;
    // check collision
    if (Intersector.overlaps(ball, player))
        Gdx.app.log("overlaps", "yes");

        //Accelerometer
        if (Gdx.input.isPeripheralAvailable(Input.Peripheral.Accelerometer)) {
            playerX -= Gdx.input.getAccelerometerX();
            playerY += Gdx.input.getAccelerometerY();
        }
    if (playerY > Gdx.graphics.getHeight() - 100) {
        playerY = Gdx.graphics.getHeight() - 100;
    }
        if (playerX < 0) {
            playerX = 0;
            playerX += Gdx.graphics.getDeltaTime() * catSpeed;
        }
        if (playerX > Gdx.graphics.getHeight() - 250) {
            playerX = Gdx.graphics.getHeight() - 250;
        } 
spriteBatch.draw(篮球,ball.x-ball.radius,ball.y-ball.radius);
spriteBatch.draw(当前帧、playerX、playerY);//在(50,50)处绘制当前帧
如果(playerY<0)playerY=0;
如果(playerY>700-80)playerY=700-80;
//检查碰撞
if(交叉点重叠(球、球员))
Gdx.app.log(“重叠”、“是”);
//加速计
if(Gdx.input.isPeripheralaAvailable(input.Peripheral.Accelerator)){
playerX-=Gdx.input.getAccelerometerX();
playerY+=Gdx.input.getAccelerometry();
}
如果(playerY>Gdx.graphics.getHeight()-100){
playerY=Gdx.graphics.getHeight()-100;
}
如果(playerX<0){
playerX=0;
playerX+=Gdx.graphics.getDeltaTime()*catSpeed;
}
如果(playerX>Gdx.graphics.getHeight()-250){
playerX=Gdx.graphics.getHeight()-250;
} 

谢谢,这里是完整的源代码:)

你说“我的代码不工作”,它怎么不工作?你的电脑着火了吗?游戏是在玩撞车时的Nickleback吗?我们看不到你在看什么。还有,为什么你用playerX和playerY而不是player.x和player.y?谢谢你,先生@ironmokey,我用了player.x和player.y,现在当猫在球上重叠时说是:)现在可以了,但是当他在球上重叠时,我怎么能阻止他呢?