【问题标题】:TextureRegion cuts texture in a wrong wayTextureRegion 以错误的方式切割纹理
【发布时间】:2015-07-05 14:08:25
【问题描述】:

我想要一个带有 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();
    }
}

【问题讨论】:

    标签: graphics libgdx game-engine


    【解决方案1】:

    如果我理解正确,您是否尝试创建 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)?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-11
      • 2011-11-12
      • 1970-01-01
      • 2016-01-11
      • 2014-04-20
      相关资源
      最近更新 更多