私は最終的に私はLDPI、MDPI、hdpi、およびxhdpi用0.75,1,1.5,2.0によってPTM率を乗じています
getResources().getResources().getDisplayMetrics().densityDpi
し、それに基づいたようなデバイス表示denitiyを取得することによってこれをしなかったわかりましたそれぞれ、
私はそれに応じてスプライトのスケールも変更しています。そして私はベースとして320X480を維持し、次に現在のxとyのピクセルとベースピクセルとの比率を乗算して配置しました。
EDIT:より良く理解するためにいくつかのコードを追加:
public class MainLayer extends CCLayer()
{
CGsize size; //this is where we hold the size of current display
float scaleX,scaleY;//these are the ratios that we need to compute
public MainLayer()
{
size = CCDirector.sharedDirector().winSize();
scaleX = size.width/480f;//assuming that all my assets are available for a 320X480(landscape) resolution;
scaleY = size.height/320f;
CCSprite somesprite = CCSprite.sprite("some.png");
//if you want to set scale without maintaining the aspect ratio of Sprite
somesprite.setScaleX(scaleX);
somesprite.setScaleY(scaleY);
//to set position that is same for every resolution
somesprite.setPosition(80f*scaleX,250f*scaleY);//these positions are according to 320X480 resolution.
//if you want to maintain the aspect ratio Sprite then instead up above scale like this
somesprite.setScale(aspect_Scale(somesprite,scaleX,scaleY));
}
public float aspect_Scale(CCSprite sprite, float scaleX , float scaleY)
{
float sourcewidth = sprite.getContentSize().width;
float sourceheight = sprite.getContentSize().height;
float targetwidth = sourcewidth*scaleX;
float targetheight = sourceheight*scaleY;
float scalex = (float)targetwidth/sourcewidth;
float scaley = (float)targetheight/sourceheight;
return Math.min(scalex,scaley);
}
}
こんにちは、私はまた、Cocos2d-アンドロイドに取り組んで、私はゲームにwrkingていますので、私はcocos2dでアンドロイドで多重解像度を処理するために、どのように適切なアイデアを得るdidntのようにXMLはNTですCCLayerとALl Imageのアセットフォルダから来ることができますか?私にいくつかの簡単なアイデアを教えてくださいこの画像を修正するにはどうすればいいですか? – ishu
あなたにはすべての画像をアセットだけに入れなければならない画面の解像度に合わせて拡大縮小します。私は基本解像度として320X480を維持してきたので、私の資産はすべて320X480に合っているので、私は幅の画面と私のベース解像度の幅を取得しているので、cocos2dからwinsizeを取得してくださいこれは私にX倍率を与えます。私はこのスケールをすべてのスプライトに適用します。あなたはそれを持っていますか? –
私はそれを持っていますが、私はすべての画像サイズの異なる別のフォルダを作成していますか? – ishu