LibGDX - Gdx.graphics.getWidth()如何返回显示表面的宽度?

use*_*250 4 java android libgdx

我想更多地了解LibGDX的内部世界.

例如在里面Graphics.java,我发现以下内容:

/** @return the width in pixels of the display surface */ 
public int getWidth (); 
Run Code Online (Sandbox Code Playgroud)

但是,我找不到getWidth()方法的源代码.

我在哪里可以找到getWidth()方法源代码?

noo*_*one 5

每个可用后端/平台都有不同的接口实现.

在LWJGL后端,实现看起来像这样:

public int getWidth () {
    if (canvas != null)
        return Math.max(1, canvas.getWidth());
    else
        return (int)(Display.getWidth() * Display.getPixelScaleFactor());
}
Run Code Online (Sandbox Code Playgroud)

实际的实现再次委托给AWT Canvas或LWJGL Display.

LibGDX中随处可见这种接口背后的一般概念.您也可以自己执行特定于平台的代码.它在维基中被描述.