每当我尝试绘制一个九点图像和一个舞台时,最后一个被调用的东西被绘制出来。我曾尝试使用正交相机,但没有成功。我尝试过:
batch.setProjectionMatrix(camera.combined);
ninePatch.draw(batch, xPos, yPos, width, height);
stage.act(delta);
stage.draw();
camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
stage.setCamera(camera)
编辑:代码
CreateQuiz类
public class CreateQuiz implements Screen{
public CreateQuiz(Quiz quiz){
this.quiz = quiz;
}
private Quiz quiz;
private FallDownPanel fallDownPanel;
private OrthographicCamera camera;
@Override
public void render(float delta) {
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
quiz.beginBatch();
fallDownPanel.render(quiz.getSpriteBatch(), delta);
quiz.endBatch();
}
@Override
public void resize(int width, int height) {
}
@Override
public void show() {
fallDownPanel = new FallDownPanel(FallDownPanel.START_LOWER_SIDE, 200, quiz.getTextureAtlas().createPatch("fallDownWindow"));
Stage stage = new Stage(fallDownPanel.getWidth(), fallDownPanel.getHeight(), false);
TextFieldStyle style = quiz.getGreenTextFieldStyle();
style.font.scale(-0.30f);
TextFieldQuiz test = new TextFieldQuiz("Hej åäö 123 !", style, 0, 2, 400, 16);
test.setTextFieldListener(new TextFieldListener() {
@Override
public void keyTyped (TextField textField, char key) {
if (key == '\n') {
textField.getOnscreenKeyboard().show(false);
}
}
});
stage.addActor(test);
Gdx.input.setInputProcessor(stage);
fallDownPanel.setStage(stage);
camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
stage.setCamera(camera);
fallDownPanel.setCamera(camera);
}
@Override
public void hide() {
}
@Override
public void pause() {
}
@Override
public void resume() {
}
@Override
public void dispose() {
}
}
FallDownPanel.class
public class FallDownPanel {
//With repeat
public FallDownPanel(int startSide, int size, NinePatch ninePatch){
Tween.registerAccessor(FallDownPanel.class, new FallDownPanelTween());
Tween.registerAccessor(Widget.class, new WidgetTween());
tweenManager = new TweenManager();
final int screenWidth = Gdx.graphics.getWidth();
final int screenHeight = Gdx.graphics.getHeight();
int target = 0;
int tweenType = 0;
if(startSide == START_LEFT_SIDE){
setSize(size, screenHeight);
xPos = -size;
yPos = 0;
target = 0;
tweenType = FallDownPanelTween.POSITION_X;
}
else if(startSide == START_RIGHT_SIDE){
setSize(size, screenHeight);
xPos = screenWidth;
yPos = 0;
target = screenWidth - size;
tweenType = FallDownPanelTween.POSITION_X;
}
else if(startSide == START_UPPER_SIDE){
setSize(screenWidth, size);
xPos = 0;
yPos = screenHeight + size;
target = screenHeight - size;
tweenType = FallDownPanelTween.POSITION_Y;
}
else if(startSide == START_LOWER_SIDE){
setSize(screenWidth, size);
xPos = 0;
yPos = -size;
target = 0;
tweenType = FallDownPanelTween.POSITION_Y;
}
Tween.to(this, tweenType, 1).target(target).start(tweenManager);
this.tweenType = tweenType;
this.startSide = startSide;
this.ninePatch = ninePatch;
}
private TweenManager tweenManager;
private NinePatch ninePatch;
private Stage stage;
private OrthographicCamera camera;
private float xPos, yPos;
private int width, height;
private int tweenType;
private int startSide;
public static final int START_LEFT_SIDE = 0, START_RIGHT_SIDE = 1, START_UPPER_SIDE = 2, START_LOWER_SIDE = 3;
public void render(SpriteBatch batch, float delta){
tweenManager.update(delta);
batch.setProjectionMatrix(camera.combined);
ninePatch.draw(batch, xPos, yPos, width, height);
stage.act(delta);
stage.draw();
}
public void setX(float x){
this.xPos = x;
}
public void setY(float y){
this.yPos = y;
}
public float getX(){
return xPos;
}
public float getY(){
return yPos;
}
public float getWidth(){
return width;
}
public float getHeight(){
return height;
}
private void setSize(int w, int h){
width = w;
height = h;
}
public Stage getStage() {
return stage;
}
public void setStage(Stage stage) {
this.stage = stage;
startWidgetTweens();
}
private void startWidgetTweens(){
float size = getShortestSide();
Array<Actor> actors = stage.getActors();
for(int i = 0; i < actors.size; i++){
Widget w = (Widget) actors.get(i);
Tween.to(w, tweenType, 1).target(0).start(tweenManager);
}
}
private float getShortestSide() {
if(startSide == START_LEFT_SIDE){
return width;
}
else if(startSide == START_RIGHT_SIDE){
return width;
}
else if(startSide == START_UPPER_SIDE){
return height;
}
else if(startSide == START_LOWER_SIDE){
return height;
}
return -1;
}
public void setCamera(OrthographicCamera camera) {
this.camera = camera;
}
}
答案 0 :(得分:0)
始终确保您一次只有一个有效Renderer
。 Renderer
是:
Batch
SpriteBatch
ShapeRenderer
Box2DDebugRenderer
如果我没错?ModelBatch
for 3D 我希望我没有忘记一个
确保在致电end()
新活动之前,始终致电begin()
另请注意,如果您致电Stage
,SpriteBatch
拥有自己的begin()
,并且会为此SpriteBatch
调用stage.draw()
。因此,请end()
之前确保Renderer
处于有效stage.draw()
如果您需要ShapeRenderer
或任何其他渲染器来绘制Actor
(可能导致调试),您必须结束stage
s SpriteBatch
, draw()
方法。确保在方法结束时再次begin()
希望这很清楚。