【发布时间】:2015-05-12 12:11:10
【问题描述】:
我有一个小组和里面的演员。我将移动和缩放动作添加到整个组。移动效果很好,但我在缩放时遇到了问题——它不会影响孩子。我认为我的小组课程中的绘图方法有问题,但我不知道是什么。
组类:
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);
}
}
演员类:
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());
}
}
【问题讨论】: