libGdx - 缩放组不影响 children
libGdx - Scaling group doesn't affect children
我有一个小组和里面的演员。我向整个组添加移动和缩放操作。移动效果很好,但我在缩放时遇到问题 - 它不影响 children。我认为我组的绘图方法有问题class但我不知道是什么。
组class:
public class LevelDetails extends Group{
float x;
float y;
TextureRegion texture;
Button button;
Button imgPrev;
Button stageName;
public LevelDetails(float x, float y, int state, TextureRegion texture){
this.x = x;
this.y = y;
float textureWidth = texture.getRegionWidth();
float textureHeight = texture.getRegionHeight();
this.texture = texture;
this.setBounds(x, y, textureWidth, textureHeight);
this.setPosition(x, y);
this.addAction(Actions.scaleBy(.75f, .75f, .5f,Interpolation.fade));
button = new Button(Assets.buttonTextReg, (int)(this.getX()+this.getWidth()/2-Assets.buttonTextReg.getRegionWidth()/2), 50, Assets.buttonTextReg.getRegionWidth(), Assets.buttonTextReg.getRegionHeight());
button.setBounds((int)(this.getX()+this.getWidth()/2-Assets.buttonTextReg.getRegionWidth()/2), 50, Assets.buttonTextReg.getRegionWidth(), Assets.buttonTextReg.getRegionHeight());
this.addActor(button);
}
@Override
public void draw(Batch batch, float parentAlpha){
batch.draw(texture, this.getX(), this.getY(), this.getOriginX(),this.getOriginY(), texture.getRegionWidth(), texture.getRegionHeight(),
this.getScaleX(), this.getScaleY(),this.getRotation());
drawChildren(batch, parentAlpha);
}
}
演员class:
public class Button extends Actor{
TextureRegion texture;
int x;
int y;
public Button (TextureRegion texture, int x, int y, int width, int height){
this.x = x;
this.y = y;
this.texture = texture;
this.setPosition(x, y);
this.setBounds(this.getX(), this.getY(), texture.getRegionWidth(), texture.getRegionHeight());
}
@Override
public void draw(Batch batch, float parentAlpha){
batch.draw(texture, this.getX(), this.getY()+this.getParent().getY(), texture.getRegionWidth(), texture.getRegionHeight());
}
}
好的,我解决了那个问题,也许它会对某人有所帮助。
组class中需要调用方法applyTransform()。现在缩放工作正常,但出现了一些移动问题——我认为起源需要修复。
@Override
public void draw(Batch batch, float parentAlpha){
batch.draw(texture, this.getX(), this.getY(), this.getOriginX(),this.getOriginY(), texture.getRegionWidth(), texture.getRegionHeight(), this.getScaleX(), this.getScaleY(),this.getRotation());
applyTransform(batch, computeTransform());
drawChildren(batch, parentAlpha);
resetTransform(batch);
}
我有一个小组和里面的演员。我向整个组添加移动和缩放操作。移动效果很好,但我在缩放时遇到问题 - 它不影响 children。我认为我组的绘图方法有问题class但我不知道是什么。
组class:
public class LevelDetails extends Group{
float x;
float y;
TextureRegion texture;
Button button;
Button imgPrev;
Button stageName;
public LevelDetails(float x, float y, int state, TextureRegion texture){
this.x = x;
this.y = y;
float textureWidth = texture.getRegionWidth();
float textureHeight = texture.getRegionHeight();
this.texture = texture;
this.setBounds(x, y, textureWidth, textureHeight);
this.setPosition(x, y);
this.addAction(Actions.scaleBy(.75f, .75f, .5f,Interpolation.fade));
button = new Button(Assets.buttonTextReg, (int)(this.getX()+this.getWidth()/2-Assets.buttonTextReg.getRegionWidth()/2), 50, Assets.buttonTextReg.getRegionWidth(), Assets.buttonTextReg.getRegionHeight());
button.setBounds((int)(this.getX()+this.getWidth()/2-Assets.buttonTextReg.getRegionWidth()/2), 50, Assets.buttonTextReg.getRegionWidth(), Assets.buttonTextReg.getRegionHeight());
this.addActor(button);
}
@Override
public void draw(Batch batch, float parentAlpha){
batch.draw(texture, this.getX(), this.getY(), this.getOriginX(),this.getOriginY(), texture.getRegionWidth(), texture.getRegionHeight(),
this.getScaleX(), this.getScaleY(),this.getRotation());
drawChildren(batch, parentAlpha);
}
}
演员class:
public class Button extends Actor{
TextureRegion texture;
int x;
int y;
public Button (TextureRegion texture, int x, int y, int width, int height){
this.x = x;
this.y = y;
this.texture = texture;
this.setPosition(x, y);
this.setBounds(this.getX(), this.getY(), texture.getRegionWidth(), texture.getRegionHeight());
}
@Override
public void draw(Batch batch, float parentAlpha){
batch.draw(texture, this.getX(), this.getY()+this.getParent().getY(), texture.getRegionWidth(), texture.getRegionHeight());
}
}
好的,我解决了那个问题,也许它会对某人有所帮助。
组class中需要调用方法applyTransform()。现在缩放工作正常,但出现了一些移动问题——我认为起源需要修复。
@Override
public void draw(Batch batch, float parentAlpha){
batch.draw(texture, this.getX(), this.getY(), this.getOriginX(),this.getOriginY(), texture.getRegionWidth(), texture.getRegionHeight(), this.getScaleX(), this.getScaleY(),this.getRotation());
applyTransform(batch, computeTransform());
drawChildren(batch, parentAlpha);
resetTransform(batch);
}