Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/381.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Andengine加载图形:为什么我的背景纹理很小而且倒置_Java_Android_Andengine - Fatal编程技术网

Java Andengine加载图形:为什么我的背景纹理很小而且倒置

Java Andengine加载图形:为什么我的背景纹理很小而且倒置,java,android,andengine,Java,Android,Andengine,最近,我开始在eclipse上使用Andengine开发android 2D游戏。 当我尝试加载我的背景纹理时,我在我的平板电脑(zync 930 plus)上得到了这个数字 这是我的密码: ResourceManager.java类 package com.example.parkmycar; import org.andengine.engine.Engine; import org.andengine.engine.camera.BoundCamera; import org.a

最近,我开始在eclipse上使用Andengine开发android 2D游戏。 当我尝试加载我的背景纹理时,我在我的平板电脑(zync 930 plus)上得到了这个数字 这是我的密码: ResourceManager.java类

    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 ;

    }

}
    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...

    } 
}

我不知道我做错了什么。

我猜您的图像大小是1024x1024(background.jpg),并且您正试图以1024的高度适应atlas纹理,但移动了10(参数0,10)

因此,请尝试替换以下内容:

BitmapTextureAtlasTextureRegionFactory.createFromAsset(mainMenuTextureAtlas,this.activity,"background.jpg",0,10) ;
为此:

BitmapTextureAtlasTextureRegionFactory.createFromAsset(mainMenuTextureAtlas,this.activity,"background.jpg",0,0) ;

i、 e:如果图集中的纹理大小完全相同,请不要将其移动10,这通常是因为加载的纹理(在本例中为background.jpg)大于BitmapTextureAtlas区域(1024x1024)。缩小背景图像的比例或增大BitmapTextureAtlas的大小(不建议将其作为1024x1024的最大大小)。任何更大的问题都可能会带来很多性能问题


同样正如erahal所指出的,如果使用1024x1024图像(位图纹理的大小)的话,您将在高度属性10上偏移图像,这将导致问题--因为新图像将被视为1024x1034而不是1024x1024,并将引发错误。

这通常是因为加载的纹理(在本例中为background.jpg)大于BitmapTextureAtlas区域。缩小背景图像的比例或增大BitmapTextureAtlas的大小,这是非常不建议的。谢谢!!我缩放了我的图像,场景。设置比例(1.5f)并且成功了!!!太棒了,没问题。尽管我不确定setScale是否理想(如果您希望最小化处理时间),因为在图像编辑工具(如GIMP)中收缩图像可能更好。但无论哪种方式都应该很酷:)是的,很好的位置,完全错过了他的价值观。不过,如果他需要背景从10开始,他应该调整他的图形大小,以便这样做。顺便说一句,你在第一段中有两次“the”。