如何设置适当的背景

时间:2013-11-24 14:42:52

标签: android background andengine live-wallpaper

我正在制作动态壁纸。我有背景问题。我无法理解如何将图像设置为背景。你能不能看一下源代码,然后说出我做错了什么。

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;


    }

1 个答案:

答案 0 :(得分: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);


}