Sign up ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I wanted to ask on how to use a sprite packed into multiple sprite sheets (multipack in texturePacker). I tried this but it doesn't work:

var bgCrumbleLayer = cc.Layer.extend({
    crumbleSheet_0:null,
    crumbleSheet_1:null,
    crumbleSheet_2:null,
    crumbleSheet_3:null,
    crumbleAction:null,
    crumbleSprite:null,

    ctor:function () {
        this._super();
        this.init();
    },

    init:function () {
        this._super();

        var winSize = cc.winSize;

        // create sprite sheet
        cc.spriteFrameCache.addSpriteFrames(res.crumble_0_plist);
        cc.spriteFrameCache.addSpriteFrames(res.crumble_1_plist);
        cc.spriteFrameCache.addSpriteFrames(res.crumble_2_plist);
        cc.spriteFrameCache.addSpriteFrames(res.crumble_3_plist);
        this.crumbleSheet_0 = new cc.SpriteBatchNode(res.crumble_0_png);
        this.crumbleSheet_1 = new cc.SpriteBatchNode(res.crumble_1_png);
        this.crumbleSheet_2 = new cc.SpriteBatchNode(res.crumble_2_png);
        this.crumbleSheet_3 = new cc.SpriteBatchNode(res.crumble_3_png);
        this.addChild(this.crumbleSheet_0);
        this.addChild(this.crumbleSheet_1);
        this.addChild(this.crumbleSheet_2);
        this.addChild(this.crumbleSheet_3);

        // init runningAction
        var crumbleFrames = [];
        for (var i = 0; i < 104; i++) {
            //var str = "crumble_" + (i < 10 ? ("0" + i) : i < 100 ? ("0" + i) : i) + ".png";
            if(i < 10){
                str = "crumble_00" + i + ".png";
            }else if(i < 100){
                str = "crumble_0" + i + ".png";
            }else {
                str = "crumble_" + i + ".png";
            }
            var frame = cc.spriteFrameCache.getSpriteFrame(str);
            crumbleFrames.push(frame);
        }

        var crumbleAnimation = new cc.Animation(crumbleFrames, 0.1);
        this.crumbleAction = new cc.repeat(new cc.Animate(crumbleAnimation), 1);
        this.crumbleSprite = new cc.Sprite("#crumble_000.jpg");
        this.crumbleSprite.attr({
            x: winSize.width/2,
            y: winSize.height/2
        });

        this.crumbleSheet_0.addChild(this.crumbleSprite);
        this.crumbleSheet_1.addChild(this.crumbleSprite);
        this.crumbleSheet_2.addChild(this.crumbleSprite);
        this.crumbleSheet_3.addChild(this.crumbleSprite);

        this.crumbleSprite.runAction(this.crumbleAction);
    }
});

Can you please advise?

share|improve this question
1  
What does "doesn't work" mean exactly? – Anko Jun 30 at 13:07
    
The animation doesn't play and this error gets thrown back: "cc.Sprite is not using the same texture" – kishikaisei Jun 30 at 16:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.