Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/367.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Sprite调整libGDX大小_Java_Libgdx - Fatal编程技术网

Java Sprite调整libGDX大小

Java Sprite调整libGDX大小,java,libgdx,Java,Libgdx,我有一个精灵,我用它来画: sprite.draw(spriteBatch); 这是有效的。。。。 我有两个唾液显示相同,但分辨率不同 假设x1=h:100px,x2=h:200px 在sprite的包装器类中,我有这样一个方法: public static void setSclae(float newScale, Sprite sprite) { // sprite.scale(newScale - sprite.getScaleX()); sprite.setScale(

我有一个精灵,我用它来画:

sprite.draw(spriteBatch);
这是有效的。。。。 我有两个唾液显示相同,但分辨率不同

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

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

public static void setSclae(float newScale, Sprite sprite) {
    // sprite.scale(newScale - sprite.getScaleX());
    sprite.setScale(newScale);
}
(我两次都试过了,都不起作用)文档:

创建包装类时,我调用如下函数:

setScale(setSide/(setWidth ? this.sprite.getBoundingRectangle().width : this.sprite.getBoundingRectangle().height));
setWidth=>boolean(要设置高度还是宽度??) 这雪碧是雪碧。原点@(0,0)

问题是:我想设置的高度,无论哪个精灵进来,50像素

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

对于x2:设置刻度(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);
}

我自己来回答。我是怎么解决的?我使用TexTureRegion实现了自己的“Sprites”类。你可能不需要所有的东西。巴斯德宾: 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

你的

弗洛里安