cocos2dx-js 动画

前端之家收集整理的这篇文章主要介绍了cocos2dx-js 动画前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

创建动画


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

        //create sprite sheet
        cc.spriteFrameCache.addSpriteFrames(res.running_plist);
        this.spriteSheet = new cc.SpriteBatchNode(res.runner_png);
        this.addChild(this.spriteSheet);

        //init runningAction
        var animFrames = [];
        for(var i=0;i<8;i++){
            var str = "runner" + i + ".png";
            var frame = cc.spriteFrameCache.getSpriteFrame(str);
            animFrames.push(frame);
        }

        var animation = new cc.Animation(animFrames,0.1);
        this.runningAction = new cc.RepeatForever(new cc.Animate(animation));

        //create the hero sprite
        this.sprite = new cc.Sprite("#runner0.png");
        this.sprite.attr({x:80,y:85});

        this.sprite.runAction(this.runningAction);
        this.addChild(this.sprite);
        //create the move action
        //var actionTo = new cc.MoveTo(2,cc.p(300,85));
        //spriteRunner.runAction(actionTo);
        //this.addChild(spriteRunner);

    }

猜你在找的Cocos2d-x相关文章