我想更多地了解 LibGDX 的内部世界。
例如在 Graphics.java
中,我发现以下内容:
/** @return the width in pixels of the display surface */
public int getWidth ();
但是,我找不到getWidth()
方法的源代码。
在哪里可以找到 getWidth()
方法的源代码?
最佳答案
对于每个可用的后端/平台,该接口(interface)都有不同的实现。
- AndroidGraphics : 对于 Android 后端。
- LwjglGraphics : 对于桌面后端。
- GwtGraphics : 对于浏览器后端
- IOSGraphics : 用于 iOS 后端。
- MockGraphics : 用于服务器后端。
- JglfwGraphics : 用于替代桌面后端。
在 LWJGL 后端,实现如下所示:
public int getWidth () {
if (canvas != null)
return Math.max(1, canvas.getWidth());
else
return (int)(Display.getWidth() * Display.getPixelScaleFactor());
}
实际的实现再次委托(delegate)给 AWT Canvas 或 LWJGL 显示。
这些接口(interface)背后的一般思想可以在 LibGDX 中随处找到。您也可以自己编写特定于平台的代码。在 the wiki 中有描述.
关于java - LibGDX - Gdx.graphics.getWidth() 如何返回显示表面的宽度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29455106/