ソースコードから理解する技術-UnderSourceCode

手を動かす(プログラムを組む)ことで技術を理解するブログ

Spritebatch、Textureregions、Spritesについて

libgdxの2D Graphicsについて学ぶため、下記のWikiを読み、写経してみました。
Spritebatch, Textureregions, and Sprites · libgdx/libgdx Wiki · GitHub

このWikiの記事のタイトルにもなっていますが、libgdxで2D Graphicsを行うには

  • Spritebatch
  • Textureregions
  • Sprite

を押さえておく必要がありそうです。

以下、上記のWikiを読んでこれらの用語についてまとめてみたメモとなります。

各用語について

引用はすべて上記WikiSpritebatch, Textureregions, and Sprites · libgdx/libgdx Wiki · GitHub からとなります。

Spritebatch

This page gives a brief overview of how images are drawn using OpenGL and how libgdx simplifies and optimizes the task through the SpriteBatch class.

画像の描写とOpenGLの使用を抽象化するのがSpriteBatch。

Texture

An image that has been decoded from its original format (e.g., PNG) and uploaded to the GPU is called a texture.

The Texture class decodes an image file and loads it into GPU memory.

デコードされGPUに読み込まれた画像のこと。

TextureRegion

The TextureRegion class (source) describes a rectangle inside a texture and is useful for drawing only a portion of the texture.

Textureの中に、さらに領域を作る。

Sprite

The Sprite class (source) describes both a texture region, the geometry where it will be drawn, and the color it will be drawn.

上記のTextureRegionと表示位置、色を保持する。

Blending

When blending is disabled, anything already on the screen at that location is replaced by the texture.

デフォルトはenableである。
塗りつぶすときにdisableにするとパフォーマンスが良くなる。

まとめ

公式Wikiを読んでみましたが、サンプルソースを写経して画像を表示しながらだと、より理解ができました。
以下が今回私が写経したソースとなります。

https://github.com/SrcHndWng/libgdxSpritebatch/tree/v1.0.0
https://github.com/SrcHndWng/libgdxSpritebatch/tree/v2.0.0

ベースのプロジェクトは
A Simple Game · libgdx/libgdx Wiki · GitHub
を参考に、描画部分をWikiの方法としてあります。