libgdx,animatios不会在android上扩展

时间:2016-06-28 13:55:39

标签: camera libgdx

我在android上测试我的应用, 我的应用程序有1个背景图像,2个动画使用TextureAtlas 它在desctop,sprite和动画都可以正常工作,但是当我在android上测试它时,sprite会正确调整大小,但是动画根本没有调整大小

     constantes.VIRTUAL_WIDTH=1920;
constantes.VIRTUAL_HEIGHT=1080;

.....

    public static void show() {
 camera = new OrthographicCamera(constantes.VIRTUAL_WIDTH, constantes.VIRTUAL_HEIGHT); //Aspect Ratio Maintenance
    batch = new SpriteBatch();
                    texturafundo = new Texture("cenarios/penhasco.jpg");
                    spriteFundo = new Sprite(texturafundo);
                    spriteFundo.setSize(Gdx.graphics.getWidth(),Gdx.graphics.getHeight());

                // animations

                   textureAtlas = new TextureAtlas(Gdx.files.internal("anima/rio.txt"));
                   animacao = new Animation(1/10f, textureAtlas.getRegions());

                  textureAtlas2 = new TextureAtlas(Gdx.files.internal("anima/portal.txt"));
                  animacao2 = new Animation(1/10f, textureAtlas2.getRegions());
}
public void render(float delta) {
           // update camera
        camera.update();


        // set viewport
        Gdx.gl.glViewport((int) viewport.x, (int) viewport.y,
        (int) viewport.width, (int) viewport.height);

        Gdx.gl.glClearColor(0, 0, 0, 1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);


        elapsedTime+=delta;

          batch.begin();



            spriteFundo.draw(batch);
            //sesenha animacao 1
            batch.draw(animacao.getKeyFrame(elapsedTime, true), 0, 0);
            batch.draw(animacao2.getKeyFrame(elapsedTime, true), 788, 249);


        batch.end();

    }

    public void resize(int width, int height) {


           float aspectRatio = (float)width/(float)height;
            float scale = 1f;
            Vector2 crop = new Vector2(0f, 0f);

            if(aspectRatio > constantes.ASPECT_RATIO) {
                scale = (float) height / (float) constantes.VIRTUAL_HEIGHT;
                crop.x = (width - constantes.VIRTUAL_WIDTH * scale) / 2f;
            } else if(aspectRatio < constantes.ASPECT_RATIO) {
                scale = (float) width / (float) constantes.VIRTUAL_WIDTH;
                crop.y = (height - constantes.VIRTUAL_HEIGHT * scale) / 2f;
            } else {
                scale = (float) width / (float) constantes.VIRTUAL_WIDTH;
            }

            float w = (float) constantes.VIRTUAL_WIDTH * scale;
            float h = (float) constantes.VIRTUAL_HEIGHT * scale;
            viewport = new Rectangle(crop.x, crop.y, w, h);


    }

0 个答案:

没有答案