Storm Asdg Storm Asdg - 5 months ago 28
Java Question

How do I make a button appear and disappear?Libgdx

I want my button to appear whenever an object reaches a certain position, that object is a sprite that is generated every second:

public void create() {
if(spritePosition>700) {

public void render() {
if (condition==true) {

The problem is that when the games starts no Sprite is generated yet, so the result is an error. I'm also thinking of calling the
method on the render method but it would generate a new button every frame because it's called constantly.


A simple way to let your button "disappear" is to just set its position to some position outside of the visible screen area.

For example something like:

buttonObj.setPosition(-1000, -1000);

To make it visible again you can just set the real coordinates again!