2013年5月8日水曜日

AndEngineを使った描画(背景塗りつぶし)

AndEngineで画面描画してみる。
とりあえず背景の塗りつぶしのみ。

1.MainActivityを編集
  こんな感じ。
package com.example.andenginetest;

import org.andengine.engine.camera.Camera;
import org.andengine.engine.options.EngineOptions;
import org.andengine.engine.options.ScreenOrientation;
import org.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
import org.andengine.entity.scene.Scene;
import org.andengine.entity.scene.background.Background;
import org.andengine.ui.activity.SimpleBaseGameActivity;
import org.andengine.util.color.Color;


public class MainActivity extends SimpleBaseGameActivity
{
 private final int CAMERA_WIDTH = 480;
 private final int CAMERA_HEIGHT = 800;

 @Override
 public EngineOptions onCreateEngineOptions()
 {
  //描画範囲のインスタンス化
  Camera camera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);

  EngineOptions eo = new EngineOptions(
    //タイトルバー非表示
    true,
    //縦画面固定
    ScreenOrientation.PORTRAIT_FIXED,
    //縦横比保持したまま最大まで拡大
    new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT),
    //描画範囲
    camera
    );

  return eo;
 }

 @Override
 protected void onCreateResources()
 {
 }

 @Override
 protected Scene onCreateScene()
 {
  Scene scene = new Scene();
  
  //背景真っ青
  scene.setBackground(new Background(Color.BLUE));

  return scene;
 }

}

2.実行
  
実行画面

動いた。


疑問:

  • SimpleLayoutGameActivityってのもあるらしい。
    レイアウトファイル(xml)を使うときに使うらしい。よく調べてない。

スポンサーリンク

Related Posts Plugin for WordPress, Blogger...