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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
| var HelloWorldLayer = cc.Layer.extend({ sprite:null, ctor:function (index) { this._super(); var backMenu = new cc.MenuItemFont("返回",this.backCall,this); backMenu.setPosition(backMenu.width/2,cc.winSize.height-backMenu.height/2); var menu = new cc.Menu(backMenu); this.addChild(menu); menu.setPosition(0,0); var lizi; switch(index){ case 1: lizi = new cc.ParticleFire(); break; case 2: lizi = new cc.ParticleFireworks(); break; case 3: lizi = new cc.ParticleFlower(); break; case 4: lizi = new cc.ParticleGalaxy(); break; case 5: lizi = new cc.ParticleMeteor(); break; case 6: lizi = new cc.ParticleSpiral(); break; case 7: lizi = new cc.ParticleSnow(); break; case 8: lizi = new cc.ParticleSmoke(); break; case 9: lizi = new cc.ParticleSun(); break; case 10: lizi = new cc.ParticleRain(); break; case 11: lizi = new cc.ParticleExplosion(); break; } lizi.texture=cc.textureCache.addImage("res/ballfire.plist.png"); lizi.setPosition(200,200); this.addChild(lizi); lizi.setTag(1); return true; }, backCall:function(){ cc.director.runScene(new MenuLayer()); }, onEnter:function () { this._super(); cc.eventManager.addListener({ event:cc.EventListener.TOUCH_ONE_BY_ONE , swallowTouches:true, onTouchBegan:this.touchbegan, onTouchMoved:this.touchmoved, onTouchEnded:this.touchended },this); return true; }, touchbegan:function (touch,event) { var x = touch.getLocationX(); var y = touch.getLocationY(); event.getCurrentTarget().getChildByTag(1).setPosition(x,y); return true; }, touchmoved:function (touch,event) { var x = touch.getLocationX(); var y = touch.getLocationY(); event.getCurrentTarget().getChildByTag(1).setPosition(x,y); return true; }, touchended:function () {
} });
var MenuLayer = cc.Layer.extend({ onEnter:function () { this._super(); var size = cc.winSize; var file = new cc.MenuItemFont("火焰粒子",this.enterLayer,this); file.setPosition(size.width/2,size.height-file.height/2-20); file.setTag(1); var yanhua = new cc.MenuItemFont("烟花粒子",this.enterLayer,this); yanhua.setPosition(size.width/2,file.getPositionY()-yanhua.height/2-20); yanhua.setTag(2); var flower = new cc.MenuItemFont("花粒子",this.enterLayer,this); flower.setPosition(size.width/2,yanhua.getPositionY()-flower.height/2-20); flower.setTag(3); var star = new cc.MenuItemFont("星系粒子",this.enterLayer,this); star.setPosition(size.width/2,flower.getPositionY()-star.height/2-20); star.setTag(4); var flowerStar = new cc.MenuItemFont("流星粒子",this.enterLayer,this); flowerStar.setPosition(size.width/2,star.getPositionY()-flowerStar.height/2-20); flowerStar.setTag(5); var rotation = new cc.MenuItemFont("漩涡粒子",this.enterLayer,this); rotation.setPosition(size.width/2,flowerStar.getPositionY()-rotation.height/2-20); rotation.setTag(6); var snow = new cc.MenuItemFont("雪粒子",this.enterLayer,this); snow.setPosition(size.width/2,rotation.getPositionY()-snow.height/2-20); snow.setTag(7); var smoke = new cc.MenuItemFont("烟粒子",this.enterLayer,this); smoke.setPosition(size.width/2,snow.getPositionY()-smoke.height/2-20); smoke.setTag(8); var sun = new cc.MenuItemFont("太阳粒子",this.enterLayer,this); sun.setPosition(size.width/2,smoke.getPositionY()-sun.height/2-20); sun.setTag(9); var rain = new cc.MenuItemFont("雨粒子",this.enterLayer,this); rain.setPosition(size.width/2,sun.getPositionY()-rain.height/2-20); rain.setTag(10); var explosion = new cc.MenuItemFont("爆炸粒子",this.enterLayer,this); explosion.setPosition(size.width/2,rain.getPositionY()-explosion.height/2-20); explosion.setTag(11); var menu = new cc.Menu(file,yanhua,flower,star,flowerStar,rotation,snow,smoke,sun,rain,menu,explosion); menu.setPosition(0,0); this.addChild(menu); }, enterLayer:function(obj){ var layer = new HelloWorldLayer(obj.tag); cc.director.runScene(layer); } });
var HelloWorldScene = cc.Scene.extend({ onEnter:function () { this._super(); var layer = new MenuLayer(); this.addChild(layer); } });
|