【发布时间】: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);
}
【问题讨论】: