Can't change Actor's position on screen












0















I was wishing to custom positioning a button on the screen of menu using LibGDX so I added the button directly to the stage but the button not keep exactly in the position that I specify. He appers exceeding the 0 x position of the screen with one part truncated. What can be causing that? Drawing a line with ShapeRender that seems to follow the exact position specidied.



16/11/2018 09:23
The constructor



public Menu(Jogo jogo) {
this.jogo = jogo;


this.camera = new OrthographicCamera();
this.camera.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
camera.position.set(0,0,0);
viewport = new ScreenViewport(camera);

estagio = new Stage(viewport);
System.out.println(viewport.getScreenX());
System.out.println("Posicao c:" +camera.position.x);
camera.position.set(0,0,0);
camera.update();
Gdx.input.setInputProcessor(estagio);
des = new ShapeRenderer();
yLinha = 320 - 39;

// botaoNovo = new TextButton("Novo", new Skin());
}


The show method:



 @Override
public void show() {
// Table tabela = new Table();
// tabela.setFillParent(true);
// tabela.setDebug(true);
// estagio.addActor(tabela);

Skin skin = new Skin(Gdx.files.internal("skin/clean-crispy-ui.json"));

botaoNovo = new TextButton("Novo jogo", skin);
estagio.addActor(botaoNovo);
// Vector2 cordS = viewport.unproject(new Vector2(11,50));//estagio.screenToStageCoordinates(new Vector2(11, 50));

// System.out.println("Estagio x 11:" + cordS.x);
botaoNovo.setPosition(40, 320-50);
botaoNovo.setWidth(largura);
System.out.println(botaoNovo.getX());
botaoNovo.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
jogo.setScreen(new TelaJogo(jogo));
}
});
}


The render method:



@Override
public void render(float delta) {
Gdx.gl.glClearColor(0, 0, 0.2f, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

camera.update();

jogo.batch.setProjectionMatrix(camera.combined);
jogo.batch.begin();
//Etim que largura = 50
jogo.fontB.draw(jogo.batch, "JI Zabelê", (240 - 50) / 2, 320 - 20);
jogo.batch.end();

if (estado == INICIANDO) {
des.setProjectionMatrix(camera.combined);
des.begin(ShapeRenderer.ShapeType.Line);
des.setColor(0, 1, 0, 0);
des.line(10, 320 - 40, 10, yLinha);
yLinha--;
if (yLinha == 320 - 80) {
System.out.println("Linha completa. iniciar botões");
estado = CRESCENDO_BOTOES;
}
des.end();
} else if (estado == CRESCENDO_BOTOES) {
botaoNovo.setWidth(largura);
largura++;
estagio.act();
estagio.draw();
//jogo.batch.begin();
//botaoNovo.draw(jogo.batch,0);
//jogo.batch.end();
if (largura == 60) ;
estado = 2;
} else if (estado == 2) {
// jogo.batch.begin();
// botaoNovo.draw(jogo.batch,0);
// jogo.batch.end();
estagio.act();
estagio.draw();
}


// if (Gdx.input.isTouched()) {
// this.jogo.setScreen(new TelaJogo(jogo));
// }
}









share|improve this question

























  • Hello and welcome to SO. Could you please share some of your relevant code?

    – Alexander
    Nov 15 '18 at 22:06











  • I added a few pieces of code to the question.

    – Antônio Diego Silva
    Nov 16 '18 at 11:39
















0















I was wishing to custom positioning a button on the screen of menu using LibGDX so I added the button directly to the stage but the button not keep exactly in the position that I specify. He appers exceeding the 0 x position of the screen with one part truncated. What can be causing that? Drawing a line with ShapeRender that seems to follow the exact position specidied.



16/11/2018 09:23
The constructor



public Menu(Jogo jogo) {
this.jogo = jogo;


this.camera = new OrthographicCamera();
this.camera.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
camera.position.set(0,0,0);
viewport = new ScreenViewport(camera);

estagio = new Stage(viewport);
System.out.println(viewport.getScreenX());
System.out.println("Posicao c:" +camera.position.x);
camera.position.set(0,0,0);
camera.update();
Gdx.input.setInputProcessor(estagio);
des = new ShapeRenderer();
yLinha = 320 - 39;

// botaoNovo = new TextButton("Novo", new Skin());
}


The show method:



 @Override
public void show() {
// Table tabela = new Table();
// tabela.setFillParent(true);
// tabela.setDebug(true);
// estagio.addActor(tabela);

Skin skin = new Skin(Gdx.files.internal("skin/clean-crispy-ui.json"));

botaoNovo = new TextButton("Novo jogo", skin);
estagio.addActor(botaoNovo);
// Vector2 cordS = viewport.unproject(new Vector2(11,50));//estagio.screenToStageCoordinates(new Vector2(11, 50));

// System.out.println("Estagio x 11:" + cordS.x);
botaoNovo.setPosition(40, 320-50);
botaoNovo.setWidth(largura);
System.out.println(botaoNovo.getX());
botaoNovo.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
jogo.setScreen(new TelaJogo(jogo));
}
});
}


The render method:



@Override
public void render(float delta) {
Gdx.gl.glClearColor(0, 0, 0.2f, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

camera.update();

jogo.batch.setProjectionMatrix(camera.combined);
jogo.batch.begin();
//Etim que largura = 50
jogo.fontB.draw(jogo.batch, "JI Zabelê", (240 - 50) / 2, 320 - 20);
jogo.batch.end();

if (estado == INICIANDO) {
des.setProjectionMatrix(camera.combined);
des.begin(ShapeRenderer.ShapeType.Line);
des.setColor(0, 1, 0, 0);
des.line(10, 320 - 40, 10, yLinha);
yLinha--;
if (yLinha == 320 - 80) {
System.out.println("Linha completa. iniciar botões");
estado = CRESCENDO_BOTOES;
}
des.end();
} else if (estado == CRESCENDO_BOTOES) {
botaoNovo.setWidth(largura);
largura++;
estagio.act();
estagio.draw();
//jogo.batch.begin();
//botaoNovo.draw(jogo.batch,0);
//jogo.batch.end();
if (largura == 60) ;
estado = 2;
} else if (estado == 2) {
// jogo.batch.begin();
// botaoNovo.draw(jogo.batch,0);
// jogo.batch.end();
estagio.act();
estagio.draw();
}


// if (Gdx.input.isTouched()) {
// this.jogo.setScreen(new TelaJogo(jogo));
// }
}









share|improve this question

























  • Hello and welcome to SO. Could you please share some of your relevant code?

    – Alexander
    Nov 15 '18 at 22:06











  • I added a few pieces of code to the question.

    – Antônio Diego Silva
    Nov 16 '18 at 11:39














0












0








0








I was wishing to custom positioning a button on the screen of menu using LibGDX so I added the button directly to the stage but the button not keep exactly in the position that I specify. He appers exceeding the 0 x position of the screen with one part truncated. What can be causing that? Drawing a line with ShapeRender that seems to follow the exact position specidied.



16/11/2018 09:23
The constructor



public Menu(Jogo jogo) {
this.jogo = jogo;


this.camera = new OrthographicCamera();
this.camera.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
camera.position.set(0,0,0);
viewport = new ScreenViewport(camera);

estagio = new Stage(viewport);
System.out.println(viewport.getScreenX());
System.out.println("Posicao c:" +camera.position.x);
camera.position.set(0,0,0);
camera.update();
Gdx.input.setInputProcessor(estagio);
des = new ShapeRenderer();
yLinha = 320 - 39;

// botaoNovo = new TextButton("Novo", new Skin());
}


The show method:



 @Override
public void show() {
// Table tabela = new Table();
// tabela.setFillParent(true);
// tabela.setDebug(true);
// estagio.addActor(tabela);

Skin skin = new Skin(Gdx.files.internal("skin/clean-crispy-ui.json"));

botaoNovo = new TextButton("Novo jogo", skin);
estagio.addActor(botaoNovo);
// Vector2 cordS = viewport.unproject(new Vector2(11,50));//estagio.screenToStageCoordinates(new Vector2(11, 50));

// System.out.println("Estagio x 11:" + cordS.x);
botaoNovo.setPosition(40, 320-50);
botaoNovo.setWidth(largura);
System.out.println(botaoNovo.getX());
botaoNovo.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
jogo.setScreen(new TelaJogo(jogo));
}
});
}


The render method:



@Override
public void render(float delta) {
Gdx.gl.glClearColor(0, 0, 0.2f, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

camera.update();

jogo.batch.setProjectionMatrix(camera.combined);
jogo.batch.begin();
//Etim que largura = 50
jogo.fontB.draw(jogo.batch, "JI Zabelê", (240 - 50) / 2, 320 - 20);
jogo.batch.end();

if (estado == INICIANDO) {
des.setProjectionMatrix(camera.combined);
des.begin(ShapeRenderer.ShapeType.Line);
des.setColor(0, 1, 0, 0);
des.line(10, 320 - 40, 10, yLinha);
yLinha--;
if (yLinha == 320 - 80) {
System.out.println("Linha completa. iniciar botões");
estado = CRESCENDO_BOTOES;
}
des.end();
} else if (estado == CRESCENDO_BOTOES) {
botaoNovo.setWidth(largura);
largura++;
estagio.act();
estagio.draw();
//jogo.batch.begin();
//botaoNovo.draw(jogo.batch,0);
//jogo.batch.end();
if (largura == 60) ;
estado = 2;
} else if (estado == 2) {
// jogo.batch.begin();
// botaoNovo.draw(jogo.batch,0);
// jogo.batch.end();
estagio.act();
estagio.draw();
}


// if (Gdx.input.isTouched()) {
// this.jogo.setScreen(new TelaJogo(jogo));
// }
}









share|improve this question
















I was wishing to custom positioning a button on the screen of menu using LibGDX so I added the button directly to the stage but the button not keep exactly in the position that I specify. He appers exceeding the 0 x position of the screen with one part truncated. What can be causing that? Drawing a line with ShapeRender that seems to follow the exact position specidied.



16/11/2018 09:23
The constructor



public Menu(Jogo jogo) {
this.jogo = jogo;


this.camera = new OrthographicCamera();
this.camera.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
camera.position.set(0,0,0);
viewport = new ScreenViewport(camera);

estagio = new Stage(viewport);
System.out.println(viewport.getScreenX());
System.out.println("Posicao c:" +camera.position.x);
camera.position.set(0,0,0);
camera.update();
Gdx.input.setInputProcessor(estagio);
des = new ShapeRenderer();
yLinha = 320 - 39;

// botaoNovo = new TextButton("Novo", new Skin());
}


The show method:



 @Override
public void show() {
// Table tabela = new Table();
// tabela.setFillParent(true);
// tabela.setDebug(true);
// estagio.addActor(tabela);

Skin skin = new Skin(Gdx.files.internal("skin/clean-crispy-ui.json"));

botaoNovo = new TextButton("Novo jogo", skin);
estagio.addActor(botaoNovo);
// Vector2 cordS = viewport.unproject(new Vector2(11,50));//estagio.screenToStageCoordinates(new Vector2(11, 50));

// System.out.println("Estagio x 11:" + cordS.x);
botaoNovo.setPosition(40, 320-50);
botaoNovo.setWidth(largura);
System.out.println(botaoNovo.getX());
botaoNovo.addListener(new ChangeListener() {
@Override
public void changed(ChangeEvent event, Actor actor) {
jogo.setScreen(new TelaJogo(jogo));
}
});
}


The render method:



@Override
public void render(float delta) {
Gdx.gl.glClearColor(0, 0, 0.2f, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

camera.update();

jogo.batch.setProjectionMatrix(camera.combined);
jogo.batch.begin();
//Etim que largura = 50
jogo.fontB.draw(jogo.batch, "JI Zabelê", (240 - 50) / 2, 320 - 20);
jogo.batch.end();

if (estado == INICIANDO) {
des.setProjectionMatrix(camera.combined);
des.begin(ShapeRenderer.ShapeType.Line);
des.setColor(0, 1, 0, 0);
des.line(10, 320 - 40, 10, yLinha);
yLinha--;
if (yLinha == 320 - 80) {
System.out.println("Linha completa. iniciar botões");
estado = CRESCENDO_BOTOES;
}
des.end();
} else if (estado == CRESCENDO_BOTOES) {
botaoNovo.setWidth(largura);
largura++;
estagio.act();
estagio.draw();
//jogo.batch.begin();
//botaoNovo.draw(jogo.batch,0);
//jogo.batch.end();
if (largura == 60) ;
estado = 2;
} else if (estado == 2) {
// jogo.batch.begin();
// botaoNovo.draw(jogo.batch,0);
// jogo.batch.end();
estagio.act();
estagio.draw();
}


// if (Gdx.input.isTouched()) {
// this.jogo.setScreen(new TelaJogo(jogo));
// }
}






android libgdx






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 16 '18 at 11:32







Antônio Diego Silva

















asked Nov 15 '18 at 21:52









Antônio Diego SilvaAntônio Diego Silva

62




62













  • Hello and welcome to SO. Could you please share some of your relevant code?

    – Alexander
    Nov 15 '18 at 22:06











  • I added a few pieces of code to the question.

    – Antônio Diego Silva
    Nov 16 '18 at 11:39



















  • Hello and welcome to SO. Could you please share some of your relevant code?

    – Alexander
    Nov 15 '18 at 22:06











  • I added a few pieces of code to the question.

    – Antônio Diego Silva
    Nov 16 '18 at 11:39

















Hello and welcome to SO. Could you please share some of your relevant code?

– Alexander
Nov 15 '18 at 22:06





Hello and welcome to SO. Could you please share some of your relevant code?

– Alexander
Nov 15 '18 at 22:06













I added a few pieces of code to the question.

– Antônio Diego Silva
Nov 16 '18 at 11:39





I added a few pieces of code to the question.

– Antônio Diego Silva
Nov 16 '18 at 11:39












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53328398%2fcant-change-actors-position-on-screen%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53328398%2fcant-change-actors-position-on-screen%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Florida Star v. B. J. F.

Danny Elfman

Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues