LibGDX - 如何让我的屏幕显示" LEVEL COMPLETE"?

时间:2014-11-30 17:04:41

标签: android libgdx sprite collision detection

我希望Android设备上的游戏屏幕更改为显示“LEVEL COMPLETE”的屏幕。我在中间创建了一个带有此消息的.png文件,当播放器标志(为了碰撞检测,两者都被建模为矩形)。这是我的Flag类

public class Flag extends GameObject {

private Sprite spr;
private Rectangle playerRect;
private boolean isOverlapping;
Player player;
private Rectangle flagRect;

public Flag(Sprite spr, float xPos, float yPos) {
    super(spr, xPos, yPos);
    player = Player.getInstance(null);
    setxPos(xPos);
    setyPos(yPos);
    flagRect = new Rectangle(getxPos(), getyPos(), getSprite().getWidth(),
            getSprite().getHeight());
}

public void update() {

    playerRect = new Rectangle(player.getxPos(), player.getyPos(), player
            .getSprite().getWidth(), player.getSprite().getHeight());
    isOverlapping = playerRect.overlaps(flagRect);
    if(isOverlapping) {
...
}
}

}

我把levelComplete.png放在我的资源文件夹中,我不知道从哪里开始。有什么建议?非常感谢

2 个答案:

答案 0 :(得分:0)

您只需从图片中制作Texture,然后使用SpriteBatch在屏幕上绘制。{1}}。这可以通过以下方式实现:

public Texture levelComplete = new Texture(Gdx.files.internal("assets/imageName.png"));
public SpriteBatch batch = new SpriteBatch();

public render(){
    batch.begin();
    if(isOverlapping){
        batch.draw(levelComplete, x, y);
    }else{
        // render game
    }
    batch.end();
}

请注意,您可能需要放置一些计时器并在5秒后停止绘制Texture或者放置某种“确定”按钮。否则你将陷入同样的​​Texture

答案 1 :(得分:0)

而不是创建包含您的文字的图像"等级完成"您可以使用BitmapFont在屏幕上用您喜欢的任何字体将其写下来

首先选择你的字体(你可以使用像 Hiero 这样的工具生成你想要的任何字体) 将它们放在资产文件中并使用这行代码加载它们

textFont = new BitmapFont(Gdx.files.internal("nameFont.fnt"), gdx.files.internal("nameFont.png"), false);

然后你只需将文字写在你想要的位置

textFont.draw(spritebatch, "Level Complete", x, y)
希望它会有所帮助!