如何使用單獨的精靈來實現libgdx動畫或textures.I嘗試作爲指定here在一個TexturePacker包裝圖像,也使一個PNG文件和映射文件來做到這一點,但它是因爲只有3張圖像需要動畫,所以效果不理想。請告訴我如何使用個人圖像或紋理進行動畫製作。動畫libgdx使用單獨的紋理
1
A
回答
1
好的首先,如果你有3張照片,你想創建一種精靈,他們確實需要相同的尺寸。我會把它作爲一種演員來實施。如果你不喜歡演員的想法,只需刪除擴展並添加位置和大小。還要將act
更改爲update
並刪除draw(...,...)
的覆蓋。
public class IndividualSprite extends Actor {
private Array<Texture> textures; //meight change it to TextureRegions which also contains a texture but sizes and positions
private float intervaltime = 0;
private float interval;
private int count = 0;
/**
* Varargs<br>
* @param timeIntervall
* @param t
* Varargs. Parse all textures here as list or simply with ,t1
* ,t2 , t3
*/
public IndividualSprite(float timeIntervall, Texture... t) {
this.interval = timeIntervall;
this.textures = new Array<Texture>();
for (Texture texture : t) {
this.textures.add(texture);
}
// now sett default width height and pos
this.setX(0);
this.setY(0);
this.setWidth(textures.get(0).getWidth());
this.setWidth(textures.get(0).getHeight());
}
public void addTexture(Texture... t) {
for (Texture texture : t) {
this.textures.add(texture);
}
}
public void deleteTexture(Texture... t) {
for (Texture texture : t) {
this.textures.removeValue(texture, true);
}
}
public void setInterval(float i) {
this.interval = i;
}
@Override
public void act(float delta) {
super.act(delta);
this.intervaltime += delta;
if (this.intervaltime >= interval) {
if (count == textures.size) {
count = 0;
} else {
count++;
}
this.intervaltime = 0;
}
}
@Override
public void draw(SpriteBatch batch, float alpha) {
batch.begin();
batch.draw(textures.get(count), getX(), getY(), getWidth(), getHeight());
batch.end();
}
}
但是一個演員,你可以給他行動移動或任何。它是一種自定義的雪碧。這只是一種方法。應該有更多,甚至更好。您還可以擴展Sprite類並更改其它東西,以便使用多個Texture等。試試吧。這是演員解決方案或非演員解決方案,如果你改變我提到的事情。別忘了打電話給.act/update
,否則它不會顯示第一個FirstTexture
。
0
找到了答案如下所述:
region1 = new TextureRegion(texture1);
region2 = new TextureRegion(texture2);
region3 = new TextureRegion(texture3);
animation = new Animation(0.08f, region1, region2, region3);
相關問題
- 1. Libgdx紋理動畫
- 2. libGDX動畫效果紋理區域
- 3. LibGDX:垂直滾動紋理
- 4. 使用TextureAtlas的LibGdx動畫
- 5. libgdx - 簡單重複的紋理(setWrap())
- 6. LIBGDX - 紋理故障
- 7. LibGDX - 圓形紋理
- 8. LibGdx紋理包裝
- 9. libGDX紋理「拉伸」
- 10. 切割紋理libgdx
- 11. 圓形紋理libGdx
- 12. 紋理紋理圖集和動畫
- 13. 紋理打包動畫圖像/ Sprite工作表有效 - Libgdx
- 14. LibGDX - 使用FBO進行紋理貼圖
- 15. 使用libgdx模型紋理錯誤
- 16. 使用libgdx繪製紋理多邊形
- 17. 使用libgdx製作字體的動態紋理
- 18. LibGdx不使用紋理(混合OpenGL本機和LibGDX)
- 19. 四與動畫紋理LWJGL
- 20. 2D OpenGL動畫紋理(Android)
- 21. 紋理沒有動畫
- 22. 關於Threejs紋理動畫
- 23. 從一個紋理文件中獲取單獨的紋理
- 24. libGDX陣列紋理錯誤
- 25. libgdx SpriteBatch渲染到紋理
- 26. Libgdx 3D紋理透明度
- 27. LibGDX紋理可繪製?
- 28. Libgdx遊戲 - 紋理縮放
- 29. Android Studio Libgdx黑色紋理
- 30. LibGDX重複紋理區域
感謝您抽出interest.I另一個簡單的代碼做了。 –