2016年1月20日水曜日

Androidで画像読み込み時に勝手に拡大されないため

Androidで画像読み込み時に、勝手に拡大される事があります。
それを防ぐために、 BitmapFactory.Options で inScaled = false を設定します

// ビットマップの読み込み
private Bitmap readBitmap(Context context, String name) {
    int resID=context.getResources().getIdentifier(
            name,"drawable",context.getPackageName());

    BitmapFactory.Options opt = new BitmapFactory.Options();
    opt.inScaled = false;
    return BitmapFactory.decodeResource(
            context.getResources(),resID, opt);
}

2016年1月19日火曜日

AndroidでAssetsフォルダのリソースを読み込む

AndroidでAssetsフォルダのリソースを読み込むサンプルを書いてみました

public ArrayList<String> loadData() {

ArrayList<String> array_data = new ArrayList<String>();
String fileName = String.format("data.csv");
AssetManager am = this.getResources().getAssets();
InputStream is = null;
BufferedReader br = null;
String str = ""; // ファイルから読み込んだテキスト

try {
try {
// assetsフォルダ内のファイルをオープンする
is = am.open(fileName);
br = new BufferedReader(new InputStreamReader(is));

while((str = br.readLine() != NULL) {
// 1行ずつ読み込んで追加する
array_data.put(str);
}
} finnaly {
if(br != null) br.close();
if(is != null)  is.close();
}
} catch (FileNotFoundException e) {
return null;
} catch (IOException e) {
return null;
}

return array_data;
}

2016年1月17日日曜日

Cocos2d-x 画面の縦長固定・横長固定

1.iPhoneアプリ
General -> Deployment Infoをクリック
Device Orientationを編集します

・縦長固定の場合 Portrait をクリック
・横長固定の場合 Landscape Left、Landscape Rightのどちらかをクリック

2.Androidアプリ
Android Studioを開きます。

app/manifests/AndroidManifest.xmlを編集します

<activity>の中に、縦長固定の場合は、android:screenOrientation="portrait" とします。
横長固定の場合は、android:screenOrientation="landscape" とします。

2016年1月13日水曜日

Android Studioでリソース用にAssetsフォルダを追加する

Android Studioでリソース用にAssetsフォルダを追加する

CSVデータなどの置き場所として、AndroidアプリではAssetsフォルダを使用するケースが多いです。
Android StudioでAssetesフォルダを追加するには、

File -> New -> Folder -> Assets Folder

で追加します。

2016年1月8日金曜日

Cocos2d-x プロジェクトの作成

Cocos2d-x プロジェクトの作成

プロジェクの作成

% cocos new TestGame -p jp.mobaroid.TestGame -l cpp -d ~/workspace

ビルドと実行

% cocos run -s ~/workspace/TestGame -p ios
% cocos run -s ~/workspace/TestGame -p android

引数の意味
・-s : プロジェクトのディレクトリ
・-p : ビルドするプラットフォーム ios、androidなど

最初に実行する場合、色々なリンクファイルがあるので10分くらいかかる事もあります。