繁体   English   中英

如何从Blank Constructor中绘制LibGDX Sprite

[英]How to draw LibGDX Sprite from Blank Constructor

我正试图在LibGDX中绘制一个Sprite 如果我使用指定要使用的纹理的构造函数,我可以这样做,例如

Sprite sprite = new Sprite(new Texture(Gdx.files.internal("path")));

但如果我改为使用Sprite(); 然后尝试使用setTexture和/或setRegion ,不绘制图片。 API表示在绘制任何内容之前需要设置“纹理,纹理区域,边界和颜色”。 我已经调用了setTexturesetRegionsetColor尽管没有绘制任何东西。

主要问题:如果我使用默认的Sprite()构造函数,之后我必须做什么才能确保它绘制到屏幕上(在SpriteBatch )?

我假设代码需要执行与Sprite(Texture)ctor相同的步骤:

public Sprite (Texture texture) {
    this(texture, 0, 0, texture.getWidth(), texture.getHeight());
}

public Sprite (Texture texture, int srcX, int srcY, int srcWidth, int srcHeight) {
    if (texture == null) throw new IllegalArgumentException("texture cannot be null.");
    this.texture = texture;
    setRegion(srcX, srcY, srcWidth, srcHeight);
    setColor(1, 1, 1, 1);
    setSize(Math.abs(srcWidth), Math.abs(srcHeight));
    setOrigin(width / 2, height / 2);
}

这些都是公共方法。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM