【问题标题】:How to set proper background如何设置合适的背景
【发布时间】:2013-11-24 14:42:52
【问题描述】:

我正在制作动态壁纸。我的背景有问题。我不明白如何将图像设置为背景。能否请您查看源代码,并说出我做错了什么。

私有静态最终 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;


    }

【问题讨论】:

  • 你在调用 createSceneCallback 吗?

标签: android background andengine live-wallpaper


【解决方案1】:
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);


}

【讨论】:

    猜你喜欢
    • 2019-05-05
    • 1970-01-01
    • 2015-06-04
    • 2013-02-25
    • 1970-01-01
    • 1970-01-01
    • 2012-03-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多