Sprite square = new Sprite(new Texture("texture"));
渲染
float squareWidth = camera.viewportWidth/squaresOnWidth;
float squareHeight = camera.viewportHeight/squaresOnHeight;
square.setWidth(squareWidth);
square.setHeight(squareHeight);
batch.begin(); `
for(int y = 0; y < squaresOnHeight; y++){
for(int x = 0; x < squaresOnWidth; x++){
square.setX(x * squareWidth);
square.setY(y * squareHeight);
square.draw(batch);
}
}
batch.end();
这应该输出纹理的网格,未经测试。
如果你想创建流畅的动画你一定要看看UniveralTweenEngine,这里有什么可以做一个演示:http://www.aurelienribon.com/universal-tween-engine/gwt/demo.html
如果你想在按钮网格来代替。
OrthoGraphicCamera camera = new OrthoGraphicCamera();
camera.setToOrtho(false, yourViewportWidth, yourViewportHeight);
camera.translate(xPos, yPos);
Stage stage = new Stage(your wanted stage width, your wanted stage height, false, batch);
stage.setCamera(camera);
for(int y = 0; y < buttonsOnHeight; y++){
for(int x = 0; x < buttonsOnWidth; x++){
stage.addActor(new TextButton("" + x + y * buttonsOnWidth, textButtonStyle);
}
}
渲染
float buttonWidth = camera.viewportWidth/buttonsOnWidth;
float buttonHeight = camera.viewportHeight/buttonsOnHeight;
for(int y = 0; y < buttonsOnHeight; y++){
for(int x = 0; x < buttonsOnWidth; x++){
TextButton button = stage.getActors().get(x + y * buttonsOnWidth);
button.setX(x * buttonWidth);
button.setY(y * buttonHeight);
button.setWidth(buttonWidth);
button.setHeight(buttonHeight);
}
}
然后绘制阶段,请注意您应停止当前正在运行,因为舞台有它自己的batch.begin()和batch.end()的任何批次。您可以在stage.draw();之后再次启动批处理。
stage.act(delta);
stage.draw();
好吧,所以你不要使用舞台。但是,如何在没有舞台的情况下添加按钮?或者有可能只有一个阶段只覆盖部分屏幕? – tomet
答案已被编辑,这是你的意思吗? – thetheodor
谢谢你的努力。我想要一个Sprites和一些按钮下面的网格。所以我需要以某种方式渲染。 – tomet