昆明网站建设咨询,网站设计的销售,中国建设银行下载官方网站,wordpress 可视化建站背景#xff1a;本来打算把第三篇和第四篇合并都一起#xff0c;但以前计划分开#xff0c;就还是分来吧#xff1b;一般的游戏涉及到关卡的话#xff0c;一般都会建立一个数组来存放各种定义参数#xff0c;消灭星星关卡比较容易#xff0c;不需要建立数组#xff0c;… 背景 本来打算把第三篇和第四篇合并都一起但以前计划分开就还是分来吧一般的游戏涉及到关卡的话一般都会建立一个数组来存放各种定义参数消灭星星关卡比较容易不需要建立数组只有两个参数level和target而且这两个参数还存在函数关系target1000*level1*level/2,只要知道第几关就可以得到该关的目标分数比如第三关目标分数就是 1000*31*3/26000; 因为这样的函数关系你会发现越往后越难过关怪不得笔者一直达不到10000分ps1 CocosEditor已发布新版本现在提供6个实战demo学习包括flappy popstar fruitninjamoonwarrorisfruitattacktestjavascript2 代码是基于javascript语言cocos2d-x游戏引擎cocos2d-x editor手游开发工具完成的3 运行demo需要配置好CocosEditor暂不支持其他工具。demo是跨平台的可移植运行androidioshtml5网页等。源代码下载请到代码集中营下载(第三四篇合并 分数和关卡)http://blog.makeapp.co/?p319不同平台下的效果图windows、html5、androidwindowsmac平台html5网页android平台代码分析1 全局参数在主函数Main.js 如下定义当前关卡和当前关卡得到的分数如果游戏没有退出两个参数值一直保持不变也可以通过这样的方法在两个场景之间传递值[javascript]view plaincopycurrentLevel 1; currentLevelScore 0; 2 MainLayer.js里面onEnter函数初始化当前关卡和目标分数获得的总分目标分数就是上面说的函数 this.targetScore 1000 * (1 currentLevel) * currentLevel / 2;[javascript]view plaincopyMainLayer.prototype.onEnter function () { cc.log(onEnter); this.pauseNode.setZOrder(120); //init starsthis.initStarTable(); //stagethis.stageFont.setString(currentLevel ); //target scorethis.targetScore 1000 * (1 currentLevel) * currentLevel / 2; this.targetFont.setString(this.targetScore ); //scorethis.totalScore currentLevelScore; this.scoreFont.setString(this.totalScore ); //score tipthis.scoreTipLabel.setVisible(false); this.tipLabel.setVisible(false); this.tipLabel.setZOrder(10); //best scorethis.bestScore sys.localStorage.getItem(starBestScore); if (this.bestScore ! null this.bestScore ! undefined) { this.bestScore Number(this.bestScore); } else { this.bestScore 0; } this.bestScoreFont.setString(this.bestScore ); } 3 游戏结束时检测是否胜利 如果胜利下一个加1currentLevel 1; 下一关基础分数是这关的总分currentLevelScore this.totalScore; 在MainLayer.js里面笔者已经定义过关卡精灵nextSprite3秒后让它显示里面还有一个移动动画7s后重新进入下一关MainLayer.js 如果失败关卡和分数都清空初始化回到开始界面[javascript]view plaincopyMainLayer.prototype.winStar function () { if (this.isClear true) { cc.AudioEngine.getInstance().playEffect(PS_MAIN_SOUNDS.win); cc.Toast.create(this.rootNode, Win, 3); currentLevel 1; currentLevelScore this.totalScore; this.nextSprite.setZOrder(100); var that this; this.rootNode.scheduleOnce(function () { that.nextLevelLabel.setString(level currentLevel ); that.nextTargetLabel.setString(target 1000 * (1 currentLevel) * currentLevel / 2); that.nextSprite.runAction(cc.Sequence.create( cc.MoveTo.create(1, cc.p(0, 0)), cc.DelayTime.create(2), cc.MoveTo.create(1, cc.p(-730, 0)) )) }, 3); this.rootNode.scheduleOnce(function () { cc.BuilderReader.runScene(, MainLayer); }, 7); } else { cc.AudioEngine.getInstance().playEffect(PS_MAIN_SOUNDS.gameover); currentLevel 1; currentLevelScore 0; cc.Toast.create(this.rootNode, lost, 2); this.rootNode.scheduleOnce(function () { cc.BuilderReader.runScene(, StartLayer); }, 2) } if (this.totalScore this.bestScore) { sys.localStorage.setItem(starBestScore, this.totalScore ); } } 就这些还是这么简单:-Dcocos2d-x跨平台游戏引擎cocos2d-x是全球知名的游戏引擎 引擎在全球范围内拥有众多开发者涵盖国内外各知名游戏开发商。目前Cocos2d-x引擎已经实现横跨ios、Android、Bada、MeeGo、BlackBerry、Marmalade、Windows、Linux等平台。编写一次到处运行分为两个版本 cocos2d-c和cocos2d-html5 本文使用了后者cocos2d-x 官网http://cocos2d-x.org/cocos2d-x 资料下载 http://cocos2d-x.org/downloadCocosEditor开发工具CocosEditor它是开发跨平台的手机游戏工具运行window/mac系统上javascript脚本语言基于cocos2d-x跨平台游戏引擎, 集合代码编辑场景设计动画制作字体设计还有粒子物理系统地图等等的而且调试方便和实时模拟CocosEditor 下载介绍和教程http://blog.csdn.net/touchsnow/article/details/19070665CocosEditor官方博客http://blog.makeapp.co/ 转载于:https://blog.51cto.com/makeapp628/1398396