0

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>
musikov
  • 640
  • 1
  • 4
  • 13
Keith Power
  • 13,891
  • 22
  • 66
  • 135

2 Answers2

2

I used

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

instead of

this.sprite = cc.Sprite.createWithSpriteFrameName("player-stand-f-0");
musikov
  • 640
  • 1
  • 4
  • 13
Keith Power
  • 13,891
  • 22
  • 66
  • 135
0
// create sprite sheet
cc.SpriteFrameCache.getInstance().addSpriteFrames(spritesheet_plist); // add Spritesheet Plist 
var SpriteSheet = cc.SpriteBatchNode.create(spritesheet_png);  // add Spritesheet Png
this.addChild(SpriteSheet,1);

// Push the frames for animation
var animFrames = [];
for (var i = 0; i < 6; i++) {
    var str = "sequence_" + i + ".png";
    var frame = cc.SpriteFrameCache.getInstance().getSpriteFrame(str);
    animFrames.push(frame);
}


// taadaa ...!!  Animate the sprites
var animation = cc.Animation.create(animFrames, 0.06);
var sprite = cc.Sprite.createWithSpriteFrameName("sequence_0.png");
sprite.setAnchorPoint(0.5,0.5); // optional
sprite.setScale(1.0,1.0); // optional
sprite.setPosition(widhthPostion, heightPosition);
sprite.runAction(cc.RepeatForever.create(cc.Animate.create(animation)));
SpriteSheet.addChild(sprite,1);
Aritra Das
  • 416
  • 3
  • 4