【问题标题】:Sprite resize libGDX精灵调整大小 libGDX
【发布时间】:2014-02-18 13:45:37
【问题描述】:

我有一个精灵,我用它来绘制:

sprite.draw(spriteBatch);

这行得通.... 我有两个显示相同但分辨率不同的恶意...

假设 x1 = h:100px,x2= h:200px

在精灵的包装类中,我有一个这样的方法:

public static void setSclae(float newScale, Sprite sprite) {
    // sprite.scale(newScale - sprite.getScaleX());
    sprite.setScale(newScale);
}

(我都试过了,都没有用)文档:http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/g2d/Sprite.html#setScale(float)

在创建包装类时,我这样调用函数:

setScale(setSide/(setWidth ? this.sprite.getBoundingRectangle().width : this.sprite.getBoundingRectangle().height));

setWidth => boolean(你想设置高度还是宽度??) 这个。精灵是精灵。原点@(0,0)

问题是:我想设置高度,不管是哪个精灵进来,都为50px...

对于 x1:setScale(50/100) -> 0.5f

对于 x2:setScale(50/200) -> 0.25f

为什么这段代码不起作用??

感谢您的帮助

你的,

弗洛里安

PS:这里是包装类的构造函数:

 public Drawable(Sprite sprite, Vector2 position, Anchor anchor, float setSide, boolean setWidth, boolean flipH, boolean flipV) {
    this.sprite = new Sprite(sprite);
    this.sprite.setOrigin(0, 0);
    setPosition(anchor, position.x, position.y);
    setScale(setSide / (setWidth ? this.sprite.getBoundingRectangle().width : this.sprite.getBoundingRectangle().height));
    this.sprite.flip(flipV, flipH);
}

【问题讨论】:

    标签: java libgdx


    【解决方案1】:

    我会自己回答。我是怎么解决的?我使用 TexTureRegion 实现了我自己的“Sprites”类。你可能不需要所有东西。巴斯宾:http://pastebin.com/1Y25HFBm IGameObject 接口如下。 [你不需要 IIntersect 接口...

    import com.badlogic.gdx.graphics.g2d.SpriteBatch;
    
    public interface IGameObject {
    
    public static enum Anchor {TopLeft, MiddleLeft, LowLeft, TopMiddle, MiddleMiddle, LowMiddle, TopRight, MiddleRight, LowRight}
    
    public void Update(GameTime.GameTimeArgs gameTimeArgs);
    
    public void Draw(SpriteBatch spriteBatch);
    
    public void setPosition(Anchor a, float x, float y);
    
    public void setScale(float newScale);
    
    public String toString();
    }
    

    希望对你有所帮助:D

    你的,

    弗洛里安

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-19
      • 1970-01-01
      相关资源
      最近更新 更多