TextureRegion以错误的方式切割纹理

时间:2015-07-05 14:08:26

标签: graphics libgdx game-engine

我想要一个带有3个矩形的背景纹理,我想用它们创建动画, - texture

但是第一个矩形以适当的方式切割,另外两个以愚蠢的方式切割     Proper way,     Dumb way #1,     Dumb way #2

这是我的代码。

    public class MainMenu implements Screen{

    Texture background_main;
    TextureRegion[] background_textures;
    Animation background_animation;
    SpriteBatch batch;
    TextureRegion current_frame; 
    float stateTime;
    BobDestroyer game;
    OrthographicCamera camera;

    public MainMenu(BobDestroyer game){
       this.game = game;
}

    @Override
    public void show() {
        camera = new OrthographicCamera();
        camera.setToOrtho(true, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
        batch = new SpriteBatch();
        background_main = new Texture(Gdx.files.internal("main_menu_screen/Background.png"));
        background_textures = new TextureRegion[3];

        for(int i = 0; i<3; i++){
            background_textures[i] = new TextureRegion(background_main,0, 0+72*i, 128, 72+72*i);
        }
        background_animation = new Animation(2f,background_textures);
    }

    @Override
    public void render(float delta) {
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
        stateTime += Gdx.graphics.getDeltaTime(); 
        current_frame = background_animation.getKeyFrame(stateTime, true);
        batch.begin(); 
        batch.draw(current_frame,0, 0,Gdx.graphics.getWidth(),Gdx.graphics.getHeight());    
        batch.end();
    }
}

1 个答案:

答案 0 :(得分:0)

如果我理解正确,您是否尝试创建相同宽度/高度的3个TextureRegions?如果是,您的问题可能是:

new TextureRegion(background_main,0, 0+72*i, 128, 72+72*i)

我想你想要:

new TextureRegion(background_main,0, 0+72*i, 128, 72)

因为128x72是你的下一个TextureRegions的宽度/高度(不是x / y位置),你不希望它们都具有相同的高度(72)而不是高度变化(72 + 72 * i)吗? / p>