gpt4 book ai didi

java - libGdx - 缩放组不会影响子级

转载 作者:行者123 更新时间:2023-11-30 03:31:15 25 4
gpt4 key购买 nike

我有一个团体和里面的 Actor 。我向整个组添加移动和缩放 Action 。搬家效果很好,但我在缩放方面遇到了问题——它不会影响 child 。我认为我的小组课上的绘图方法有问题,但我不知道是什么问题。

小组类(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);

}

}

Actor 类别:

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());
}
}

最佳答案

好的,我解决了这个问题,也许会对某人有所帮助。

需要调用组类方法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);
}

关于java - libGdx - 缩放组不会影响子级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28974169/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com