Forum > C# > {SOLVED}SpriteSheets and plists not being read correctly?

{SOLVED}SpriteSheets and plists not being read correctly?

By cach Posted 2012-05-24 16:16 Comments 3
cach
  • Posts: 5

Hi,

I’m porting a game project from cocos2d-x for iPhone and I ran into a problem while working with spritesheets.

All spritesheets were made with TexturePacker using the “allow rotation” option wich means that all the frames are squished together to save memory ( more info here: http://www.raywenderlich.com/2361/how-to-create-and-optimize-sprite-sheets-in-cocos2d-with-texture-packer-and-pixel-formats ). Using these spritesheets works fine on cocos2d-x iphone and android as they can handle the rotation and position the frame correctly, but the XNA version does not, and the frames are shown without the correct rotation.

I don’t know if this is a mistake of cocos2d XNA, or it was never meant to work with this kind of spritesheets. That would mean I have to repack every spritesheet differently and I would rather avoid that.

Any guidance is appreciated.

cach
  • Posts: 5

#1 RE: 2012-05-24 17:43

Well, it seems it was an error with cocos2d XNA, because the .plist parser skips over the “rotated” propriety.
This can be fixed by changing line 142 in CCSAXParser.cs

if (name == "key" || name == "integer" || name == "real" || name == "string")
{
   string value = xmlReader.ReadElementContentAsString();
   buffer = Encoding.UTF8.GetBytes(value);
   textHandler(this, buffer, buffer.Length);
   endElement(this, name);
}

into

if (name == "key" || name == "integer" || name == "real" || name == "string" || name == "true" || name == "false")
{
   string value = xmlReader.ReadElementContentAsString();
   buffer = Encoding.UTF8.GetBytes(value);
   textHandler(this, buffer, buffer.Length);
   endElement(this, name);
}
jwa@javatopia.com
  • Posts: 243
  • Location: Totally Evil Entertainment - San Diego

#2 RE: 2012-08-06 04:19

bump. I will look at this tomorrow to get into the next minor release.

Target: 0.1.3a (if it’s not alread in 0.1.2a).

jwa@javatopia.com
  • Posts: 243
  • Location: Totally Evil Entertainment - San Diego

#3 RE: 2012-08-07 16:41

This will go into 0.1.3a. There are some issues with the sax parser and plist data. For one, the “endElement” handler is called twice for every handled element. Next, there is no state management so you don’t have to use the “dict” tag to enclose your dictionary attributes.

Loggin to reply

Copyright © 2010 - 2013 Cocos2d-x.orgClustrmaps