(cocos2d-js游戏)测试你的反应速度----------基本逻辑(上)
发布时间:2020-12-14 19:15:40 所属栏目:百科 来源:网络整理
导读:游戏玩法:点击开始游戏,等待一个随机时间,然后背景颜色会变(在t1时刻),这时候你需要点击屏幕(在t2时刻),游戏结束。你的反应时间就是天t2-t1。 游戏逻辑: 游戏逻辑很简单,如上图所示。一共有五个界面,其实用五张图片就可以代替 主要代码: var Main
游戏玩法:点击开始游戏,等待一个随机时间,然后背景颜色会变(在t1时刻),这时候你需要点击屏幕(在t2时刻),游戏结束。你的反应时间就是天t2-t1。 游戏逻辑:
游戏逻辑很简单,如上图所示。一共有五个界面,其实用五张图片就可以代替 主要代码:
var MainLayer = cc.LayerColor.extend({ init:function() { //初始化界面 //0:点击开始界面 1:表示等待界面,2:表示在点击界面 3:结果界面 4:Too soon界面 this.flag = 0; this._super(); this.size = cc.Director.getInstance().getWinSize(); this.setColor(cc.c4(180,170,160,255)); this.showToStart(); //可触摸 this.setTouchEnabled(true); },///////////////////////////////////////////////// //处理触摸事件 ///////////////////////////////////////////////// onTouchesEnded:function(touches,event) { },onTouchesBegan:function(touches,event) { cc.log("onTouchsBegan",this.flag); switch(this.flag) { case 0:this.showWaite();break; case 1:this.showToSoon();break; case 2:this.showResult();break; case 3:this.showWaite();break; case 4:this.showWaite();break; } },//显示点击开始界面 showToStart:function() { this.sprite = cc.Sprite.create(s_ClickToStart); this.sprite.setPosition(this.size.width/2,this.size.height/2); this.addChild(this.sprite,1); this.flag = 0; },//显示等待界面 showWaite:function() { cc.log("showWaite"); this.removeAllChildren();//清除所有控件 this.unscheduleAllCallbacks();//清除定时器 this.sprite = cc.Sprite.create(s_WaiteForGreen); this.sprite.setPosition(this.size.width/2,1); this.anim = cc.Sprite.create(s_WaiteForGreenAnim) this.anim.setPosition(this.size.width/2,this.size.height/2+200); this.addChild(this.anim,1); var action = cc.Sequence.create(cc.FadeOut.create(1.0),cc.FadeIn.create(1.0)); var rep = cc.RepeatForever.create(action); this.anim.runAction(rep); this.flag = 1; //输出1-10的随机数 randomTime = Math.floor(Math.random()*10+1); this.schedule(this.showGreen,randomTime,1,0); //添加定时器 cc.log("randomTime",randomTime); },//显示点击的页面 showGreen:function() { cc.log("showGreen"); this.sprite = cc.Sprite.create(s_Click); this.sprite.setPosition(this.size.width/2,1); this.flag = 2; this.date1 = new Date();//颜色变化后,记录一个时间 },showToSoon:function() { cc.log("showToSoon"); this.unscheduleAllCallbacks(); this.sprite = cc.Sprite.create(s_TooSoon); this.sprite.setPosition(this.size.width/2,1); this.flag = 3; },//显示结果界面 showResult:function() { this.unscheduleAllCallbacks(); this.date2 = new Date();//记录点击时间 time = this.date2.getTime() - this.date1.getTime(); this.sprite = cc.Sprite.create(s_Result); this.sprite.setPosition(this.size.width/2,1); cc.log("showResult",time); this.timeLabel = cc.LabelTTF.create(time+"ms","Arial",70); this.timeLabel.setColor(255,255,255); this.timeLabel.setPosition(this.size.width/2,this.size.height/2) this.addChild(this.timeLabel,1); this.flag = 4; } }); /////////////////////////////////////////////////// var MainScene = cc.Scene.extend({ onEnter:function(){ this._super(); var layer = new MainLayer(); layer.init() this.addChild(layer); } }); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 设置oracle 连接提示符
- xml(3)--dom4j实现crud操作
- objective-c – 在保留自动布局约束的同时更换NSView
- C#中使用@声明变量示例(逐字标识符)
- ruby-on-rails – Bundler与Rubygems 2.0不兼容.请升级到Bu
- Preventing Back Button Default When Navigating Views in
- 在foreach中的Enumerable.Where中无法访问C#对象属性
- c# – 向字节数组添加零字节的最简单方法是什么?
- WinCC flexible 2008 SP4 奇怪现象1
- Ruby Shoes GUI:不断更新段落