簡體   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