1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
| var HelloWorldLayer = cc.Layer.extend({ process:0, sprite:null, size:cc.winSize, ctor:function () { this._super(); var allpic=["res/bg.jpg", "res/h2.png", "res/walk01.png", "res/walk02.png", "res/walk03.png", "res/walk04.png", "res/walk05.png"]; for(var n=0;n<allpic.length;n++) { cc.textureCache.addImageAsync(allpic[n],this.callback,this); } return true; }, callback:function(){ this.process++; var width = this.size.width-50; this.drawProgress(1,(this.size.width-width)/2,100,width,50,cc.color(255,0,0,255),5,cc.color(255,0,0,0)); var np=this.process*100/7; this.drawProgress(2,(this.size.width-width)/2,100,width*(np/100),50,cc.color(255,0,0,255),5,cc.color(255,0,0,255)); if(np==100){ this.removeChild(100,true); var spbg=new cc.Sprite("res/bg.jpg"); this.addChild(spbg); var sphero=new cc.Sprite("res/h2.png"); this.addChild(sphero); spbg.setPosition(cc.winSize.width/2,cc.winSize.height/2); sphero.setScale(0.3); sphero.setPosition(200,200); } }, drawProgress:function(tag,x,y,width,height,borderColor,border,fillColor){ if(this.getChildByTag(tag)!=null){ this.removeChildByTag(tag); } var rect = new cc.DrawNode(); this.addChild(rect); rect.setTag(tag); var points = [ cc.p(x,y), cc.p(x+width,y), cc.p(x+width,y+height), cc.p(x,y+height) ]; rect.drawPoly(points, fillColor, border,borderColor); } });
var HelloWorldScene = cc.Scene.extend({ onEnter:function () { this._super(); var layer = new HelloWorldLayer(); this.addChild(layer); } });
|