我有一个自定义的ImageTextButton,我首先将按钮渲染到FrameBuffer,然后使用frameBuffer.getColorBufferTexture()进行绘制。我并不是真的想要这样做但是我使用带有这个按钮的自定义着色器来创建一些视觉效果,而我能够实现它的唯一方法是使用FrameBuffer。我很惊讶地发现这实际上非常流畅和快速,整个过程在慢速设备上需要1-2ms,并且有几个实例不会导致任何帧速率下降,所以我很满意这一点。
我遇到的问题是当我在ImageTextButton上启用剪辑时(使用setClip(true))。这样做的原因是按钮可以改变宽度,我希望它能够在按钮的边界内剪切文本。如果我禁用FrameBuffer并正常渲染,这部分也能很好地工作。如果我将2结合起来,那么裁剪过程似乎会混淆,结果要么是文本还是文本的非常小部分。
所以这是相关的代码。我认为这是因为我设置FrameBuffer和SpriteBatch大小/投影矩阵只是为了处理活动区域(为了提高效率)但是如果我不修改任何一个并使用相同的批/投影矩阵,那么FrameBuffer管理整个屏幕,结果仍然相同。
-(void) receivedNotification:(NSNotification*) notification
{
NSLog(@"Notification Received ");
}
对于长码,很抱歉,它实际上已经严重削减了必要的部件。 一如既往的帮助非常感谢!
答案 0 :(得分:0)
经过多次播放后,我发现的解决方案可能在其他情况下非常有用,这是通过顶点修改实现BitmapFontCache的真实剪辑,不涉及剪刀!因此,如果有人发现这个有用,那么代码就是;
float xStart = ...start position of clip
float xEnd = ...end position of clip
//vertex offset numbers
int x_1 = 0, x_2 = 5, x2_1 = 10, x2_2 = 15;
int u_1 = 3, u_2 = 8, u2_1 = 13, u2_2 = 18;
for (int j = 0, n = pageCount; j < n; j++) {
int c = cache.getVertexCount(j);
int newIdx = 0;
if (c > 0) { // ignore if this texture has no glyphs
float[] vertices = cache.getVertices(j);
for(int i = 0; i < vertices.length; i+=20){
//if any of the vertices are outside the label, don't put them in the new cache
if(vertices[i+x2_1] > xStart && vertices[i+x_1] < xEnd){
for(int k = 0; k < 20; k++){
clippedVerts[j][newIdx+k] = vertices[i+k];
}
//case on major left glyph
if(vertices[i+x_1] < xStart){
float xDiff = vertices[i+x2_1]-xStart; //difference between right of glyph and clip
float xRatio = xDiff / (vertices[i+x2_1]-vertices[i+x_1]);
float uDiff = vertices[i+u2_1] - vertices[i+u_1];
float newU = vertices[i+u2_1] - uDiff*xRatio;
clippedVerts[j][newIdx+x_1] = xStart;
clippedVerts[j][newIdx+x_2] = xStart;
clippedVerts[j][newIdx+u_1] = newU;
clippedVerts[j][newIdx+u_2] = newU;
}
//case on major right glyph
if(vertices[i+x2_1] > xEnd){
float xDiff = xEnd-vertices[i+x_1]; //difference between left of glyph and clip
float xRatio = xDiff / (vertices[i+x2_1]-vertices[i+x_1]);
float uDiff = vertices[i+u2_1] - vertices[i+u_1];
float newU_2 = vertices[i+u_1] + uDiff*xRatio;
clippedVerts[j][newIdx+x2_1] = xEnd;
clippedVerts[j][newIdx+x2_2] = xEnd;
clippedVerts[j][newIdx+u2_1] = newU_2;
clippedVerts[j][newIdx+u2_2] = newU_2;
}
newIdx += 20;
}
}
}
clippedIdx[j] = newIdx;
}
for (int j = 0, n = pageCount; j < n; j++) {
int idx = clippedIdx[j];
if (idx > 0) { // ignore if this texture has no glyphs
float[] vertices = clippedVerts[j];
batch.draw(regions.get(j).getTexture(), vertices, 0, idx);
}
}