【问题标题】:libGdx - Scaling group doesn't affect childrenlibGdx - 缩放组不影响儿童
【发布时间】: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());
    }
}

【问题讨论】:

    标签: java libgdx actor


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-02
      相关资源
      最近更新 更多