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