1000字范文,内容丰富有趣,学习的好帮手!
1000字范文 > cocos creator中开发的新手引导

cocos creator中开发的新手引导

时间:2022-05-28 06:02:12

相关推荐

cocos creator中开发的新手引导

使用cocos creator 制作新手引导

其中的点击屏蔽借用了这位大哥CocosCreator 新手引导 圆圈圈中部分能点击 ,圈外点击无效的分享,表示感谢

首先用一个类来管理新手引导的数据,代码如下

var GuideData = {//外部不可直接访问_isGuide: true, _stageID: 101,_stageStep: 1,_isComplete: false,initData: function () {if (!!tempData) {this._isGuide = tempData.is_guide;this._stageID = tempData.stage_id;this._stageStep = tempData.stage_step;this._isComplete = tempData.is_complete;} else {// console.log("!!! not have guide info use default", this.isGuide, this.stageName, this.stageStep); }},setData: function (ID, step, isComplete) {this._stageID = ID;this._stageStep = step;this._isComplete = isComplete;this.UpdateGuideInfo();},UpdateGuideInfo: function () {var stageInfo = {is_guide: this._isGuide,stage_id: this._stageID,stage_step: this._stageStep,is_complete: this._isComplete,}},getGuideInfo: function () {var stageInfo = {isGuide: this._isGuide,stageID: this._stageID,stageStep: this._stageStep,isComplete: this._isComplete}return stageInfo;},getGuideState: function () {return this._isGuide;},setCloseGuide: function () {this._isGuide = false;this.UpdateGuideInfo();},setOpenGuide: function () {this._isGuide = true;this.UpdateGuideInfo();},}module.exports = GuideData;

然后是一个新手引导的管理类,用于引导的切换,关闭

var guideData = require("GuideData");cc.Class({extends: ponent,properties: {shieldingBtn: cc.Node,},onLoad() {this.guides = this.node.children;this.shieldingBtnContol();},/*** 打开引导* @param {JSON} data 要打开的引导阶段信息 */OpenGuide: function(data) {var guide = guideData.getGuideState();var stageID = data.stageID;guideData.setData(data.stageID, data.stageStep, data.isComplete);if (guide) {this.guides.forEach(element => {if (element._name == stageID) {element.active = true;let jsName = "Guidance" + stageID;element.getComponent(jsName).InitData(data);return;}});}},/*** 切换引导* @param {JSON} event 要切换到的引导阶段信息*/ChangeGuide: function(event) {guideData.setData(event.stageID, event.stageStep, event.isComplete);this.CloseGuide(event.stageID - 1);this.OpenGuide(event);},/*** 关闭当前引导引导* @param {number} stageID 要关闭引导阶段ID */CloseGuide: function(stageID) {if (stageID == 100) {return;} else {this.guides.forEach(element => {if (element._name == stageID) {element.active = false;}});}},shieldingBtnContol: function() {var guideInfo = guideData.getGuideInfo();let finallyLottery = dataOperateFunc.getBlobMapByKey("finallyLottery");let bldg = bldgInfoData.getSingeBldgInfo(1104);if (bldg.level > 0 || (finallyLottery != undefined && finallyLottery != 1)) {this.shieldingBtn.active = false;} else {this.shieldingBtn.active = true;}},});

抽象出一个引导类,用于具体的引导任务实现,具体的引导可以通过继承改类进行修改

var guideData = require("GuideData");var IGuidance = cc.Class({extends: ponent,properties: {_isCatchTouch: true,},onLoad() {this.touchArea = cc.find("mask/touchArea", this.node);this.tipMesgLabel = cc.find("tipMessage", this.node);this.node.on(cc.Node.EventType.TOUCH_START, this.CanTouch, this);cc.game.on('LevelTwentyFour', pletionOpration, this);this.canTouch = true;},CanTouch: function (event) {if (this.canTouch) {this.OnTouchBg(event);} else {console.log("the is set can`t touch");}},OnTouchBg: function (event) {let point = event.getLocation();let retWord = this.touchArea.getBoundingBoxToWorld();let space = 40;retWord.width -= space;retWord.width = retWord.width <= 0 ? 0 : retWord.width;retWord.height -= space;retWord.height = retWord.height <= 0 ? 0 : retWord.height;if (retWord.contains(point)) {this.node._touchListener.setSwallowTouches(false);} else {this.node._touchListener.setSwallowTouches(true);}},InitData: function (data) {this.stageID = data.stageID;this.stageStep = data.stageStep;this.isComplete = data.isComplete;this.ShowGuide();},CompletionOpration: function (data) {this.stageStep = data.stageStep;this.isComplete = data.isComplete;if (data.stageID == this.stageID) {this.ShowGuide();}},ShowGuide: function () {beginnerGuide.data.forEach(element => {if (element.stage_id == this.stageID) {if (element.step == this.stageStep) {if (this.isComplete) {if (!!element.des_after) {this.tipMesgLabel.getComponent(cc.RichText).string = element.des_after;} else {}} else {if (!!element.des_front) {this.tipMesgLabel.getComponent(cc.RichText).string = element.des_front;} else {return;}}}}});},});

代码不是完整代码,记录下制作的思想,以后有了新的想法可以再来修改,希望能对有需要的人有点用,我就是个菜鸡,希望能得到大神指点,练就绝世神功。。。。。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。