I have a level scene that i allow the user to select a level.
But to move on to the next level the user must complete the level before it.
Right now the first level which is automatically unlocked.
When it is completed i want unlock the second level. and when the second level is completed, unlock the third level.
i cant think of how i would go about doing this. i thought of sharedpreferences but dont know the logic i should use for this.
i could use some help on the logic behind this.
Any can help me out?
EDIT:
In my gameplay scene when is game is completed i call this to sharedpreference
editor.putString("level_completed"+level, "unlocked");
editor.commit();
Then i do..
String levelStatus = preference.getString("level_completed:"+level, "locked");
if(levelStatus.equals("unlocked")){
}else{
if(level == 0){
box.setUserData("unlocked");
}else{
box.setColor(1.0f,0.0f,0.0f);
box.setUserData("locked");
}
}
in the level selection scene to check if the level is unlocked.
This doesnt seem to be working to well. A level that should be unlocked isnt unlocked.
There are a number of ways you could approach it. If the progression is always linear (1, 2, 3, 4) then you could just store an integer for “max unlocked level” and then update it whenever you complete a level. Otherwise, you could also have many booleans like “level 2 unlocked” and when you complete level 1, you can set “level 2 unlocked” to true. Shared Preferences is definitely a reasonable way to go.