本文整理汇总了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;
}
}