私は私がここで作っていますという一般的なプールがあります。アクティビティの外でスクリーンメトリックを取得する方法は?
public class FruitPool extends GenericPool<Sprite> {
// ===========================================================
// Constants
// ===========================================================
// ===========================================================
// Fields
// ===========================================================
private final TextureRegion mTextureRegion;
private Scene mScene;
// ===========================================================
// Constructors
// ===========================================================
public FruitPool(final TextureRegion pFruitTextureRegion, Scene mScene2) {
this.mTextureRegion = pFruitTextureRegion;
this.mScene = mScene2;
}
// ===========================================================
// Getter & Setter
// ===========================================================
// ===========================================================
// Methods for/from SuperClass/Interfaces
// ===========================================================
@Override
protected Sprite onAllocatePoolItem() {
Random rand = new Random();
//I want to get the Screens Display metrics here...
Sprite fruit = new Sprite(0, 0, this.mTextureRegion);
mScene.attachChild(fruit);
return fruit;
}
私はこのような画面表示メトリックを取得しようとしています。..
final Display display = getWindowManager().getDefaultDisplay();
CAMERA_WIDTH = display.getWidth();
CAMERA_HEIGHT = display.getHeight();
唯一の問題はあるが、私は姿を傾けることですアクティビティの外でこれを行う方法を教えてください。
これも可能ですか?またはSharedPreferenceなどを使用する必要がありますか?
私はそれについては決して考えなかった! –
私はこれを試してみましたが、 "メソッドgetWindowManager()はコンテキストタイプのために定義されていません" –
コンテキストの代わりにActicityオブジェクト(this)を渡します。コンテキストは基本的にアクティビティのスーパークラスであり、おそらくAtivityクラス –