我正在使用cocos2d-js v3.0和html5,我正在将一个plist加载到缓存中,我正在尝试从中创建一个精灵。
我收到错误
[Error] Failed to load resource: the server responded with a status of 404 (Not Found) (player-stand-f-0, line 0)
据我所知。不推荐使用.createWithSpriteFrameName,但所有示例都显示使用它。
代码:
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>
答案 0 :(得分:2)
我用过
this.sprite = new cc.Sprite("#player-stand-f-0");
而不是
this.sprite = cc.Sprite.createWithSpriteFrameName("player-stand-f-0");
答案 1 :(得分: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);