문제

I have a problem with my game. I have a map 1280x1280px . It is consisted of 40x40 tiles, so 1 tile is 32x32 pixels. The thing is that I can't scale this map to the actual screen size of my device. Is there any way to do that?

This is how I load the tmx file:

public Scene onLoadScene() {
                // TODO Auto-generated method stub
                this.mMainScene = new Scene(1);

                try
                {
                        final TMXLoader tmxLoader = new TMXLoader(this, this.mEngine.getTextureManager(),
                                                                                                                TextureOptions.BILINEAR_PREMULTIPLYALPHA);
                        this.mTMXTiledMap = tmxLoader.loadFromAsset(this,"gfx/untitled.tmx");

                        //"gfx/0_fire_drill-lvl_01.tmx"
                }
                catch(final TMXLoadException tmxle)
                {              
                        Debug.e(tmxle);
                }

                for(TMXLayer tmxLayer : this.mTMXTiledMap.getTMXLayers())
                {
                        this.mMainScene.getChild(0).attachChild(tmxLayer);
                }              

                return this.mMainScene;
        }

This is how the map loocks like: http://postimage.org/image/403w3dfnx/

The actions will happend only in the red area. Do I need to edin the map?

Thank you in advance!

도움이 되었습니까?

해결책

The issue is not with how you're generating the map, it's with your camera. Create a camera using one of AndEngine's various camera classes. (I'm a fan of the SmoothCamera.) Like this:

SmoothCamera camera = new SmoothCamera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT, 10, 10, 1.0f);

CAMERA_WIDTH and CAMERA_HEIGHT are ints for you to define. If you set these to smaller values, you'll be more zoomed in. You can also directly adjust the zoom on the camera. Like this:

camera.setZoomFactor(5.0f);

And you're probably going to want to set the camera to chase your player entity. Something like this:

camera.setChaseEntity(pChaseEntity)

Where pChaseEntity is whatever you'd like it to follow. Hope this helps.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top