cocos2d-html5

cocos2d-html5 get sprite from cache plist


I am using cocos2d-js v3.0 with html5 and I am loading a plist into cache and them I am trying to create a sprite from.

I am getting the error

[Error] Failed to load resource: the server responded with a status of 404 (Not Found) (player-stand-f-0, line 0)

As far as I am aware .createWithSpriteFrameName is deprecated but all examples show to use this.

The code:

var cache = cc.spriteFrameCache;
cache.addSpriteFrames(player.plist, player.png);

this.sprite = cc.Sprite.createWithSpriteFrameName("player-stand-f-0");
this.sprite.setPosition(new cc.Point(300,300));
this.addChild(this.sprite);

player.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>frames</key>
  <dict>
    <key>player-sit-f-0</key>
    <dict>
        <key>frame</key>
        <string>{{3,108},{77,95}}</string>
        <key>offset</key>
        <string>{0,0}</string>
        <key>rotated</key>
        <false/>
        <key>sourceColorRect</key>
        <string>{{0,0},{77,95}}</string>
        <key>sourceSize</key>
        <string>{77,95}</string>
    </dict>

Solution

  • I used

    this.sprite = new cc.Sprite("#player-stand-f-0");
    

    instead of

    this.sprite = cc.Sprite.createWithSpriteFrameName("player-stand-f-0");