本文整理匯總了Java中com.badlogic.gdx.graphics.g2d.SpriteBatch.createDefaultShader方法的典型用法代碼示例。如果您正苦於以下問題:Java SpriteBatch.createDefaultShader方法的具體用法?Java SpriteBatch.createDefaultShader怎麽用?Java SpriteBatch.createDefaultShader使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.badlogic.gdx.graphics.g2d.SpriteBatch
的用法示例。
在下文中一共展示了SpriteBatch.createDefaultShader方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: init
import com.badlogic.gdx.graphics.g2d.SpriteBatch; //導入方法依賴的package包/類
final void init() {
if(spriteBatchDefault == null) {
spriteBatchDefault = SpriteBatch.createDefaultShader();
}
}
示例2: CircularProgress
import com.badlogic.gdx.graphics.g2d.SpriteBatch; //導入方法依賴的package包/類
public CircularProgress(TextureRegion region) {
this.region = region;
/**
* 使用默認的shader
* 一般不指定ShaderProgram,我們使用SpriteBatch的時候都是使用默認的shader
*/
this.shader = SpriteBatch.createDefaultShader();
// 設置頂點數據類型為數組類型
Mesh.VertexDataType vertexDataType = Mesh.VertexDataType.VertexArray;
/**
* 隻需要處理 :頂點坐標、顏色、紋理坐標
*/
VertexAttribute[] vertexAttributes = new VertexAttribute[3];
vertexAttributes[0] = new VertexAttribute(Usage.Position, POSITION_COMPONENTS, "a_position");
vertexAttributes[1] = new VertexAttribute(Usage.ColorPacked, COLOR_COMPONENTS, "a_color");
vertexAttributes[2] = new VertexAttribute(Usage.TextureCoordinates, TEXCOORD_COMPONENTS, "a_texCoord0");
this.mesh = new Mesh(vertexDataType, false, MAX_VERTICES, MAX_INDICES, vertexAttributes);
float width = region.getRegionWidth();
float height = region.getRegionHeight();
/**
* 初始化頂點數據
*/
vertices = new float[MAX_VERTICES * TOTAL_COMPONENTS];
int idx = 0;
vertices[(idx++)] = 0;
vertices[(idx++)] = 0;
idx = idx + 3;
vertices[(idx++)] = 0;
vertices[(idx++)] = (height / 2.0f);
idx = idx + 3;
vertices[(idx++)] = (width / 2.0f);
vertices[(idx++)] = (height / 2.0f);
idx = idx + 3;
vertices[(idx++)] = (width / 2.0f);
vertices[(idx++)] = 0;
idx = idx + 3;
vertices[(idx++)] = (width / 2.0f);
vertices[(idx++)] = (-height / 2.0f);
idx = idx + 3;
vertices[(idx++)] = 0;
vertices[(idx++)] = (-height / 2.0f);
idx = idx + 3;
vertices[(idx++)] = (-width / 2.0f);
vertices[(idx++)] = (-height / 2.0f);
idx = idx + 3;
vertices[(idx++)] = (-width / 2.0f);
vertices[(idx++)] = 0;
idx = idx + 3;
vertices[(idx++)] = (-width / 2.0f);
vertices[(idx++)] = (height / 2.0f);
/**
* 初始話頂點位置 與 紋理坐標
*/
for (int i = 0; i < 9; i++) {
vertices[i * 5 + 0] = (vertices[i * 5] + (width / 2.0f));
vertices[i * 5 + 1] = (vertices[i * 5 + 1] + (height / 2.0f));
Vector2 uv = getUV(region, vertices[i * 5], vertices[i * 5 + 1]);
vertices[i * 5 + 3] = uv.x;
vertices[i * 5 + 4] = uv.y;
}
}