2011-09-24 8 views
5

andeningeを使用してゲームを開発しています。固定カメラの幅と高さandengineを使用して異なる画面解像度でゲームを実行する方法

private static final int CAMERA_WIDTH = 480; 
private static final int CAMERA_HEIGHT = 320; 

@Override 
public Engine onLoadEngine(){  
    this.mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT); 
    final Engine engine = new Engine(new EngineOptions(true, ScreenOrientation.LANDSCAPE, new FillResolutionPolicy(), this.mCamera).setNeedsSound(true));  
    return engine; 
} 

ゲームでは、建物サイズの画像は(1020x400)です。 camera_widhthとcamera_heightが480,320の場合は建物ビューが正しく表示されます。 andengine(同じ建物の画像サイズを使用)を使用して、異なる画面解像度でゲームを実行する方法。

それ以外の場合は、すべての画面解像度の建物画像を変更する必要がありますか?

答えて

5

あなたが望むのであれば、今のように固定カメラを使うことができます。 OpenGL ESはデバイス画面を満たすようにビューを拡大/縮小します。これはおそらく最も簡単な解決策ですが、アスペクト比が1.5(480/320)よりも異なるデバイスでゲームが実行されている場合、アスペクト比を変更するか、画面の上下または左右に黒いボックスを残します。私は現在、ほとんどのデバイスが1.66アスペクト比(800/480)を持っていると思う。

他のオプションが使用する:

DisplayMetrics metrics = new DisplayMetrics(); 
getWindowManager().getDefaultDisplay().getMetrics(metrics) 
CAMERA_WIDTH = metrics.widthPixels() 
CAMERA_HEIGHT = metrics.heightPixels() 

カメラのサイズを設定し、自分のスプライトにピクセルサイズと画面の画素密度(DPI)の組み合わせ(http://developer.android.com/reference/android/util/DisplayMetrics.htmlを参照)、使用.setScaleを使用しますそれに応じてそれらを拡大する。

4

Andengineゲームはネイティブデバイスに拡張します -

をので...あなたは480x320にごCAMERA_WIDTH /高さを設定し、誰かが800×480あなたのゲームである携帯電話にそれを実行する場合はスケールアップされる720×480に( 1.5倍)、80pxのマージン(上、下、左、右、またはビューの重力に応じてそれらの間に分割)があります。

アプリを使っている人のほとんどが使用されるかを決定する必要があります - 私は、800×480をターゲットとし、小さい画面にいくつかの収縮と一緒に暮らすする傾向がある - のではなく他の方法で回避...

を使用でき
1

をこのソース:

@Override 
public Engine onLoadEngine() { 
    final Display defaultDisplay = getWindow().getWindowManager().getDefaultDisplay(); 
    CAMERA_WIDTH = defaultDisplay.getWidth(); 
    CAMERA_HEIGHT = defaultDisplay.getHeight(); 
    this.mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT); 
    return new Engine(new EngineOptions(true, ScreenOrientation.PORTRAIT, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), this.mCamera)); 
} 
1

デフォルトでAndEngineは固定解像度ポリシーを必要とすると想定しています。次のリンクで与えられる。しかし、あなたはまた、

http://android.kul.is/2013/10/andengine-tutorial-dealing-with-screen-sizes.html

それとも、あなたはこのコードを追跡し、それに応じてコードを変更することができますが、それを変更することができます。 (私の好み)

// Calculate the aspect ratio ofthe device. 
float aspectRatio = (float) displayMetrics.widthPixels/(float) displayMetrics.heightPixels; 

// Multiply the aspect ratio by the fixed height. 
float cameraWidth = Math.round(aspectRatio * CAMERA_HEIGHT); 

// Create the camera using those values. 
this.mCamera = new Camera(0, 0, cameraWidth, cameraHeight); 

// Pick some value for your height. 
float cameraHeight = 320; 

// Get the display metrics object. 
final DisplayMetrics displayMetrics = new DisplayMetrics(); 

// Populate it with data about your display. 
this.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); 
関連する問題