O'Reilly logo

Cocos2d Cross-Platform Game Development Cookbook - Second Edition by Siddharth Shekar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Saving to the XML file data

To store the data in XML, we will first add the value we want to store in the players array we created. Then, we will take this modified array list and call the saveXMLGroup function, which will write the value into the XML document.

How to do it…

First, let's create the addXMLPlayer function, which will add a new player to the array, as follows:

-(void) addXMLPlayer:(Player)player {

  NSValue *value = [NSValuevalueWithBytes:&player objCType:@encode(Player)];

  [playersaddObject:value];

}

There is nothing fancy here; we are just taking the player and storing it in NSValue and then adding the value to the players array, as follows:

- (void) saveXMLGroup{ GDataXMLElement * groupElement= [GDataXMLNodeelementWithName:@"Group"]; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required