# Image-Button coordinates are busted

I have an image-button and I set its position in create in this way:

imageButton.setPosition(orthographicCamera.position.x+150,150);


The problem is that the position always changes, despite I set it in create. Also if I change device, I notice that the coordinates are busted, wrong, instead other views are right.

If I write setPositionin render, the image-button is faster than the camera, it gets away from the screen, but for other views, this doesn't happen because they follow the camera. Why?

• Do you want it to follow the camera or be static? – Charanor Jun 14 '17 at 10:51
• @Charanor follow the camera – Curio Jun 14 '17 at 10:54

There are several possible solutions to this.

Try using stage coordinates instead like so: button.setPosition(150, 150). Stage always start at (0, 0) bottom left corner.

OrthographicCamera gameCam = ...;
OrthographicCamera stageCam = ...;
Viewport viewport = new FitViewport(1280, 720, stageCam); //Constant viewport size
Stage stage = new Stage(viewport);


Then use gameCam for all of your game related stuff and use stageCam for your UI. I use a FitViewport here for our stage's viewport since it preserves aspect ratio. Makse sure to read up on Viewports to more clearly understand what viewport fits your need.

• getX()? There isn't getX(); – Curio Jun 14 '17 at 11:28
• @Curio my bad, it should just be 150. – Charanor Jun 14 '17 at 12:12
• If I change the device, it changes the position, like before – Curio Jun 14 '17 at 13:40
• @Curio could you provide some screenshots? This is probably because the viewport sizes are different but I need to see to be sure. I've also updated my answer with a potential solution (see stageCam). – Charanor Jun 14 '17 at 13:44
• I don't know if I can take some screenshots at the moment, but I can tell you that the image-button changes position but other views not. – Curio Jun 14 '17 at 14:17