正在删除sprite Libgdx Java



我有一个精灵,它被表示为用于操作和信息的矩形,上面有一个纹理。这是我的代码:

int carrotScore;
    boolean onCarrot = true;
    Rectangle carrot;
    carrotScore = 0;
carrot = new Rectangle();
        carrot.height = 100;
        carrot.width = 100;
        carrot.x = 50;
        carrot.y = 50;
if(carrot.overlaps(farmer) && onCarrot!= false){
                onCarrot = false;
                carrotScore += 1;               
            }
if(carrotScore == 2){
                game.setScreen(new Level2Complete(game));
            }
if(onCarrot = true){
                game.batch.draw(carrotTexture, 50, 50, 100, 100);
            }

然而,当我运行它并且精灵重叠时,上一个图形仍然显示并且没有消失,同时它将屏幕更改为level2Complete,所以还在计数吗?有什么想法吗?为什么它还在数胡萝卜,为什么图形没有消失?

if(onCarrot = true)

应该是

if(onCarrot == true)

您正在指定onCarrot=true,而不是检查它是否为true。

最新更新