2012-03-13 12 views
6

最近、私はAndEngineで作業を始めました。この点について、最新のドキュメント/ヘルプ資料を見つけるのは難しいです。私は例&のソースコードを経て背景画像を設定しようとしています。しかし何らかの理由で画面が空白のままです。私はこれに関連する有用な情報を見つけることができません。ここでは、コードは次のようになります。その代わりAndEngineの背景画像

SpriteBackground bg = new SpriteBackground(...); 
    scene.setBackground(bg); 

public class AndEngineActivity extends BaseGameActivity { 

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

    private Camera mCamera; 
    private TextureRegion mBgTexture; 
    private BitmapTextureAtlas mBackgroundTexture; 


    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
    } 

    @Override 
    public Engine onLoadEngine() { 
     // TODO Auto-generated method stub 
     this.mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT); 
     return new Engine(new EngineOptions(true, ScreenOrientation.LANDSCAPE, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), this.mCamera)); 
    } 

    @Override 
    public void onLoadResources() { 
     // TODO Auto-generated method stub 
     BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/"); 

     this.mBackgroundTexture = new BitmapTextureAtlas(1024, 1024, TextureOptions.DEFAULT); 
     mBgTexture = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBackgroundTexture, this, "background.png", 0, 0); 

     this.mEngine.getTextureManager().loadTextures(this.mBackgroundTexture); 

    } 

    @Override 
    public Scene onLoadScene() { 

     this.mEngine.registerUpdateHandler(new FPSLogger()); 

     final Scene scene = new Scene(); 
     final int centerX = (CAMERA_WIDTH - 
       mBgTexture.getWidth())/2; final int centerY = (CAMERA_HEIGHT - 
       mBgTexture.getHeight())/2; 
     SpriteBackground bg = new SpriteBackground(new Sprite(centerX, centerY, mBgTexture)); 
     scene.setBackground(bg); 

     return scene; 
    } 

    @Override 
    public void onLoadComplete() { 
     // TODO Auto-generated method stub 

    } 
} 

答えて

-3

削除必要

Sprite bg = new Sprite(new Sprite(centerX, centerY, mBgTexture)); 
    scene.attachChild(bg); 
+0

こんにちは、私はそれを試してみましたが、私もそれを試して、それは助けになりませんでした。何か不足していますか?他のアイデア? – Mob

+0

最終的に良いニュースが届きました。上記の添付のコードで見られるように、onCreate(..)メソッドはレイアウトを上書きしています。私は方法を削除し、それは今働いている。 – Mob

+0

さて、そうしたいとは思わない:-) – bos

5

を試してみてください。

/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 
} 
-1

次を使用します。

CCSprite background=CCSprite.sprite("car7m.jpg");