Game Development Reference
In-Depth Information
Saves the arena objects by calling the SaveObjectState() function using
a handle composed of the input parameter Handle, the “ArenaObject”
keyword, and the index i for all the elements in the m_ArenaObjectSet array, if
there is a valid element for that array index slot
4.
5.
Saves and commits the changes to the shared preferences
Listing 10-3. Saving the ArenaObject Set
void SaveSet(String Handle)
{
SharedPreferences settings = m_Context.getSharedPreferences(Handle, 0);
SharedPreferences.Editor editor = settings.edit();
for (int i = 0; i < MAX_ARENA_OBJECTS; i++)
{
// Active Status
String ActiveHandle = Handle + "Active" + i;
editor.putBoolean(ActiveHandle, m_Active[i]);
if (m_ArenaObjectSet[i] != null)
{
String ArenaObjectHandle = Handle + "ArenaObject" + i;
m_ArenaObjectSet[i].SaveObjectState(ArenaObjectHandle);
}
}
// Commit the edits!
editor.commit();
}
The LoadSet() function loads in the ArenaObject set data. (See Listing 10-4.)
The LoadSet() function does the following:
1.
Retrieves a SharedPreferences object based on the input parameter Handle
Reads in all the elements of the m_Active boolean array from the shared
preferences using a handle based on the input parameter Handle, “Active”
keyword, and the slot index
2.
Reads in the saved data by calling the LoadObjectState() function for each
element in the m_ArenaObjectSet array that has a valid object
3.
Listing 10-4. Loading the ArenaObject Set
void LoadSet(String Handle)
{
// Restore preferences
SharedPreferences settings = m_Context.getSharedPreferences(Handle, 0);
 
Search WWH ::




Custom Search