Search code examples
javaandroidandengine

Changing Variable value from another class


I have an integer(levelstatus) in class A(LevelSelectScene) and I want to change it in class B(GameScene), is it possible?

here is my code:

(Code in GameScene)

public class levelComplete()
{

levelSelectScene.getInstance.levelstatus=1;

}

LevelSelectScene has an public integer levelstatus.

and after an event happens, levelComplete will trigger and will change the value of levelstatus from null to 1.


Solution

  • Yes.

    Make your levelstatus variable as static.

    Because I guess you need to change that variable in each level class.

    That means,you are wanting to access that variable through out the whole Game(All levels).

    And also,Declare that variable in a Util class(proposing a name LevelUtil),Since it wont attach to a single level.