2015-12-30 27 views
0

我需要從libgdx的Core目錄中的類中獲取在Android文件夾下的XML文件中定義的維。如何訪問Android資源,例如在libgdx中的尺寸?

我知道我可以使用assets文件夾來訪問drawables。但是尺寸或字符串如何?

+0

爲什麼反對投票?如果你不明白這個問題,就放手吧。我敢打賭,負面投票的人甚至不知道什麼是libgdx。 – Ehsan

回答

1

您無法直接在覈心項目中訪問此類平臺特定的信息。但是,這可以通過將這些功能與Facade對接來實現,從而爲每個目標提供特定於平臺的實現。

In libgdx-wiki有一個平臺專用接口的例子。

public interface PlatformSpecificStuff { 
    public String getString(); 
    public int getDimensions(); 
} 

// In -Android project 
public class AndroidSpecificStuff implements PlatformSpecificStuff { 
    public String getString(){ 
     // do whaterver you want with the resources. 
     return "string resource"; 
    } 

    public int getDimensions(){ 
     // do whaterver you want with the resources. 
     return 42; 
    } 
} 

// In -Desktop project 
public class DesktopSpecificStuff implements PlatformSpecificStuff { 
    public String getString(){ 
     // there is no xml or any andorid specific resource 
     return null; 
    } 

    public int getDimensions(){ 
     // there is no xml or any andorid specific resource 
     return 0; 
    } 
} 

public class MyGame implements ApplicationListener { 
    private final PlatformSpecificStuff pss; 

    public MyGame(PlatformSpecificStuff pss) { 
     this.pss= pss; 
    } 
} 

更新:我不知道什麼是試圖通過得到的尺寸爲Android的資源來完成。但是你可能在錯誤的軌道上。如果你想支持多種屏幕尺寸,看看viewports

+0

我知道它一定是在文檔中的某處,但我無法找到它。謝謝! – Ehsan