Creating a Sprite from .xml file

Hi!
I’m trying to preload my sprite sheet in AppDelegate

auto spritecache = SpriteFrameCache::getInstance();
spritecache->addSpriteFramesWithFile(“sheet.xml”);

and then
RocketPlayer* RocketPlayer::create(const char PNGName)
{
RocketPlayer
sprite = new RocketPlayer();
if (sprite && sprite->initWithSpriteFrameName(PNGName))
{
sprite->autorelease();
return sprite;
}
CC_SAFE_DELETE(sprite);
return NULL;
}
but it’s crashed. With .plist files this works fine. How to use .xml file.

So we kinda have to guess the content of your xml-file?

what i have to provide to you? I have 2 files .png and .xml
The .xml file looks like:





TextureAtlas imagePath=“sheet.png”>
SubTexture name=“beam0.png” x=“143” y=“377” width=“43” height=“31”/>
SubTexture name=“beam1.png” x=“327” y=“644” width=“40” height=“20”/>
SubTexture name=“beam2.png” x=“262” y=“907” width=“38” height=“31”/>
SubTexture name=“beam3.png” x=“396” y=“384” width=“29” height=“29”/>
SubTexture name=“beam4.png” x=“177” y=“496” width=“41” height=“17”/>

Well, I have no idea why you believe cocos2d-x has to load this xml.
It supports the plist-files. The example content:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <dict>
        <key>frames</key>
        <dict>
            <key>pixel_1x1.png</key>
            <dict>
                <key>frame</key>
                <string>{{2,2},{1,1}}</string>
                <key>offset</key>
                <string>{0,0}</string>
                <key>rotated</key>
                <false/>
                <key>sourceColorRect</key>
                <string>{{0,0},{1,1}}</string>
                <key>sourceSize</key>
                <string>{1,1}</string>
            </dict>
        </dict>
        <key>metadata</key>
        <dict>
            <key>format</key>
            <integer>2</integer>
            <key>realTextureFileName</key>
            <string>pixel.png</string>
            <key>size</key>
            <string>{8,8}</string>
            <key>smartupdate</key>
            <string>$TexturePacker:SmartUpdate:17a06005c18bdbb57c23e0e87197e7c1:5fed5ceb09948693b325c05f4aaf5af7:59532eafbd20dae9dae1b618926c041b$</string>
            <key>textureFileName</key>
            <string>pixel.png</string>
        </dict>
    </dict>
</plist>

Many thanks to you!!! I will try Texture Packer.

You can also try ShoeBox. It’s free and has some other useful functionality.