2013-11-24 98 views
0

我正在處理動態壁紙。我有背景問題。我無法理解如何將圖像設置爲背景。你可以看看源代碼,並說我做錯了什麼。如何設置適當的背景

private static final int MAX_FRAMES_PER_SECOND = 16;

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

    private Camera mCamera; 
    private Scene mScene; 

    private ITextureRegion mFlowerTextureRegion;  
    private BitmapTextureAtlas mFlowerTexture; 
    private VelocityParticleInitializer<UncoloredSprite> mVelocityParticleInitializer; 


    @Override 
    public EngineOptions onCreateEngineOptions() { 

     final DisplayMetrics displayMetrics = new DisplayMetrics(); 
     WindowManager wm = (WindowManager)getSystemService(WINDOW_SERVICE); 
     wm.getDefaultDisplay().getMetrics(displayMetrics); 
     wm.getDefaultDisplay().getRotation(); 
     CAMERA_WIDTH = displayMetrics.widthPixels; 
     CAMERA_HEIGHT = displayMetrics.heightPixels; 
     this.mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT); 

     return new EngineOptions(true, ScreenOrientation.PORTRAIT_FIXED, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), this.mCamera); 
    } 

    @Override 
    public void onCreateResources(OnCreateResourcesCallback createResourcesCallback) throws Exception { 
     this.mFlowerTexture = new BitmapTextureAtlas(this.getTextureManager(),16,16, TextureOptions.BILINEAR_PREMULTIPLYALPHA);  
     this.mFlowerTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mFlowerTexture, this, "gfx/snowflake.png",0,0);  
     this.getEngine().getTextureManager().loadTexture(this.mFlowerTexture); 
     this.enableAccelerationSensor(this); 
     createResourcesCallback.onCreateResourcesFinished(); 
    } 
    @Override 
    public org.andengine.engine.Engine onCreateEngine(final 
     EngineOptions pEngineOptions) 
    { 
     return new LimitedFPSEngine(pEngineOptions, MAX_FRAMES_PER_SECOND); 

    } 


    @Override 
    public void onCreateScene(OnCreateSceneCallback createSceneCallback) throws Exception {  
     mScene= new Scene(); 

//add the background to the scene 
// I chose a black background to accentuate the red rose color 
     mScene.setBackground(new Background(0.0f, 0.0f, 0.0f)); 

// set the x y values of where the petals fall from 
     final int mParticleX = CAMERA_WIDTH/2; 
     final int mParticleY = 0; 
//Set the max and min rates that particles are generated per second 
     final int mParticleMinRate = 1; 
     final int mParticleMaxRate = 2; 
//Set a variable for the max particles in the system. 
     final int mParticleMax = 40; 


    } 
+0

你打的createSceneCallback? – jmroyalty

回答

0
private void createBackground() { 
    splash1 = new Sprite(0, 0, resourcesManager.menu_background_region, 
      vbom) { 
     @Override 
     protected void preDraw(GLState pGLState, Camera pCamera) { 
      super.preDraw(pGLState, pCamera); 
      pGLState.enableDither(); 
     } 
    }; 

    splash1.setScale(.9f);//set scaling according to your wish 
    splash1.setPosition(400, 240); 
    attachChild(splash1); 


}