Andengine加载图形:为什么我的背景纹理小且倒挂 [英] Andengine loading graphics: why is my background texture small and upside down

查看:192
本文介绍了Andengine加载图形:为什么我的背景纹理小且倒挂的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我开始对使用日食的android Andengine 2D游戏的工作。
当我尝试加载我的背景纹理,我得到这个数字在我的平板电脑(zync 930加)

这里是我的code:
ResourceManager.java类

Recently, I started working on android 2D game using Andengine on eclipse. When I try to load my background texture, I get this figure on my tablet (zync 930 plus) Here is my code: ResourceManager.java class

    package com.example.parkmycar;

import org.andengine.engine.Engine;
import org.andengine.engine.camera.BoundCamera;
import org.andengine.opengl.texture.TextureOptions;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.andengine.opengl.texture.region.ITextureRegion;
import org.andengine.opengl.vbo.VertexBufferObjectManager;


public class ResourceManager {

    private static final ResourceManager INSTANCE = new ResourceManager() ;

    public MainGameActivity activity;
    public Engine engine ;
    public BoundCamera camera ;
    public VertexBufferObjectManager vbom ;

    //Textures
    private BitmapTextureAtlas mainMenuTextureAtlas ;
    public ITextureRegion playButton,mainMenuBackground ;

    public void loadMenuResources(){
        loadMenuGraphics() ;
        //loadMenuSounds() ;

    }

    private void loadMenuGraphics(){


        BitmapTextureAtlasTextureRegionFactory.setAssetBasePath("gfx/");
        this.mainMenuTextureAtlas = new BitmapTextureAtlas(this.activity.getTextureManager(),1024,1024,TextureOptions.BILINEAR_PREMULTIPLYALPHA) ;
        this.mainMenuBackground = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mainMenuTextureAtlas,this.activity,"background.jpg",0,10) ;
        //this.playButton = BitmapTextureAtlasTextureRegionFactory.createFromAsset(mainMenuTextureAtlas,activity.getAssets(),"play.png") ;
        this.mainMenuTextureAtlas.load();
        /*try{
        this.mainMenuTextureAtlas.build(new BlackPawnTextureAtlasBuilder<IBitmapTextureAtlasSource,
                BitmapTextureAtlas>(0,0,1) ) ;
        //this.mainMenuTextureAtlas.load() ;
        }catch(TextureAtlasBuilderException e){
            Debug.e(e) ;

        }*/

    }


    public static ResourceManager getInstance() {
        return INSTANCE;
    }


    public static void prepareManager(Engine engine,MainGameActivity activity,BoundCamera camera,VertexBufferObjectManager vbom)
    {
        getInstance().engine = engine ;
        getInstance().activity=activity ;
        getInstance().camera = camera ;
        getInstance().vbom = vbom ;

    }

}

MainGameActivity.java类

    package com.example.parkmycar;

        import org.andengine.engine.Engine;
        import org.andengine.engine.LimitedFPSEngine;
        import org.andengine.engine.camera.BoundCamera;
        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.ui.activity.BaseGameActivity;

public class MainGameActivity extends BaseGameActivity {

    private BoundCamera camera ;//Bound to keep the camera focused on our player

    private ResourceManager resourceManager ;
    private float WIDTH=800 ;
    private float HEIGHT=480 ;

    @Override
    public Engine onCreateEngine(EngineOptions engineOptions){
        //Creating our customized engine
        return new LimitedFPSEngine(engineOptions,60) ;     
    }

    @Override
    public EngineOptions onCreateEngineOptions() {

        this.camera = new BoundCamera(0,0,WIDTH,HEIGHT) ;//posx,posy,width,height
        //Methods to call all that we are going to need for our game (audio...)
        EngineOptions engineOptions = new EngineOptions(true,ScreenOrientation.LANDSCAPE_FIXED,new RatioResolutionPolicy(WIDTH,HEIGHT),this.camera) ;

        //FillResolutionPolicy: structures the game to fill the resolution and devices

        engineOptions.getAudioOptions().setNeedsMusic(true) ;

            return engineOptions;
    }

    @Override
    public void onCreateResources(
            OnCreateResourcesCallback pOnCreateResourcesCallback)
            throws Exception {
        // Loads resources before the scene is shown (load textures, fonts,sounds...)==> Management
            ResourceManager.prepareManager(mEngine, this, camera, getVertexBufferObjectManager());
            resourceManager = ResourceManager.getInstance();
            resourceManager.loadMenuResources();
            pOnCreateResourcesCallback.onCreateResourcesFinished();
    }

    @Override
    public void onCreateScene(OnCreateSceneCallback pOnCreateSceneCallback)
            throws Exception {
        // Where we are supposed to create our scene (called once the oncreateResources() is finished)

    }

    @Override
    public void onPopulateScene(Scene pScene,
            OnPopulateSceneCallback pOnPopulateSceneCallback) throws Exception {
        //Where we are supposed to populate our scene with buttons, background,text, entities...

    } 
}

我不知道我做错了。

I don't know what I am doing wrong.

推荐答案

这通常是因为要装入纹理(在这种情况下background.jpg)比你BitmapTextureAtlas面积(1024×1024)更大。无论是规模下你的背景图像或增加这是不建议作为1024x1024的应该是你的最大尺寸BitmapTextureAtlas的大小。还有更大的可能会得到很多的性能问题。

This usually happens because you are loading a texture (in this case background.jpg) that is bigger than your BitmapTextureAtlas area (1024x1024). Either scale your background image down or increase the size of BitmapTextureAtlas which is not suggested as 1024x1024 should be your max size. Anything bigger you may get a lot of performance issues.

另外,作为erahal指出的那样,你在10 height属性,如果您使用的是1024×1024的图像(大小你的 BitmapTextureAtlas ),这会导致一些问题抵消你的形象 - 因为你的新形象将被视为1024x1034,而不是1024x1024的,并会引发错误

Also as erahal pointed out, you are offsetting your image on the Height attribute of 10 which will cause issues if you are using a 1024x1024 image (size of your BitmapTextureAtlas) -- because your new image will be treated as 1024x1034 instead of 1024x1024 and will throw an error.

这篇关于Andengine加载图形:为什么我的背景纹理小且倒挂的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆