精灵切割

来源:互联网 发布:fx网络什么意思 编辑:程序博客网 时间:2024/05/01 11:45

//图片路径

_currentUrl : null

/*

*  初始化

 */

_init:function(){ 

        // 随机精灵

        this._currentUrl = "res/"+parseInt(1 + Math.random()*13)+".png";

},

_buildShred: function(){

    //将一张图片添加到缓存

    var texture = cc.textureCache.addImage(this._currentUrl);

    var textureBasePoint = cc.p(0,texture.height);

    //每块碎片的宽度

    var wid = texture.width/LEVEL;

    //每块碎片的高度

    var hei= texture.height/LEVEL;

    //防止移位

    wid = wid.toFixed(5)-0.00001;

    hei = hei.toFixed(5)-0.00001;

     //按顺序切割

    for(var i=0;i<LEVEL;i++){

         for (var j = 0; j<LEVEL ; j++){

                //保存碎片

                this._sp = new Cell(texture,cc.rect(i*wid,j*hei,wid,hei), num);

                //设定碎片锚点
                this._sp.setAnchorPoint(0,1);
                this._sp.setPosition(this.A.x+i*wid ,100+texture.height - j*hei );
                this._picPanel.addChild(this._sp);
                this._shredArr.push(this._sp);

         }

    }

 

},   

0 0
原创粉丝点击