当然,jason文件是从cocosstudio中做好发布的 var AboutLayer=cc.Layer.extend({ _bg:null, _sprite:null, spark:null, _text1:null, _text2:null, ctor : function(){ this._super(); var size = cc.winSize; //添加粒子效果 , 括号内文已注册号的离子文件名(在resource内注册) this.spark = new cc.ParticleSystem(res.spark_plist); this.spark.setPosition(size.width/2,size.height/2); this.spark.setTag(110); this.addChild(this.spark); //coocstudio ui加载,括号内为已注册号的jason文件名 var loginScene = ccs.load(res.Login).node; //将loginscene对象加入到layer中。 this.addChild(loginScene); //获取按钮 var button1=loginScene.getChildByTag(92).getChildByTag(93); button1.addTouchEventListener(this._onButtonEvent, this); //获取账号 this._text1 = loginScene.getChildByTag(95).getChildByTag(98); //获取密码 this._text2 = loginScene.getChildByTag(99).getChildByTag(102); return true; }, _onButtonEvent : function(sender,type){ switch(type) { case ccui.Widget.TOUCH_BEGAN: cc.log("开始"); if (this._text1.string == "wangyi" && this._text2.string == "123") { cc.log("登陆成功"); //创建一个图层 var picture = new cc.LayerColor(cc.color(255, 0, 0, 100), 300, 200); picture.setPosition(cc.p(150, 500)); this.addChild(picture); //将文字加到图片上 var label = new cc.LabelTTF("登陆成功","",30); label.setPosition(cc.p(150,100)); picture.addChild(label); } else { cc.log("登陆失败"); } break; case ccui.Widget.TOUCH_MOVED: cc.log("移动"); break; case ccui.Widget.TOUCH_ENDED: cc.log("结束"); break; } } }); var AboutScene = cc.Scene.extend({ onEnter:function(){ this._super(); var layer = new AboutLayer(); this.addChild(layer); } });