classlibgdxboolean

LibGDX how do I use one boolean in all class


I have one class that I put the Boolean in, but I need to use it in a different class. Can anyone tell me what to do to get the boolean to work for the other classes too?

public class playbutton extends Actor
{
    public boolean on = false;

https://i.sstatic.net/8clF1.png

public void draw(Batch batch, float parentAlpha)
{
    if (on == true)`

https://i.sstatic.net/wxA3N.png


Solution

  • First of all check this post, we discourage screenshots of code and/or errors so please post code in future instead of screenshot.


    From screenshot on is non-static data member of playbutton class. You can't use non-static data member in all class.

    You need an object of playbutton, if you want to access any non-static data member.

    playbutton x=new playbutton();
    x.on=true;
    

    I'll recommend you to follow naming conventions in java for better coding experience.