TextureRegion 以错误的方式切割纹理
TextureRegion cuts texture in a wrong way
我想要一个包含 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();
}
}
如果我没理解错的话,你是想创建 3 个相同 width/height 的 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 的 width/height(不是 x/y 位置),您不希望它们都具有相同的高度 (72) 而不是不同的高度 (72+ 72*i)?
我想要一个包含 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();
}
}
如果我没理解错的话,你是想创建 3 个相同 width/height 的 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 的 width/height(不是 x/y 位置),您不希望它们都具有相同的高度 (72) 而不是不同的高度 (72+ 72*i)?