其中的点击屏蔽借用了这位大哥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: cc.Component,
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: cc.Component,
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', this.CompletionOpration, 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;
}
}
}
}
});
},
});
代码不是完整代码,记录下制作的思想,以后有了新的想法可以再来修改,希望能对有需要的人有点用,我就是个菜鸡,希望能得到大神指点,练就绝世神功。。。。。