mirror of
https://github.com/Leo501/CocosCreatorTutorial.git
synced 2026-05-31 14:39:22 +08:00
基本完善一个新手引导页面
This commit is contained in:
@@ -3,32 +3,70 @@ cc.Class({
|
||||
|
||||
properties: {
|
||||
nodeTarget: cc.Node,
|
||||
nodeMark: cc.Node,
|
||||
nodeMarkBg: cc.Node
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
this.registerEvent();
|
||||
this.node.on('touchstart', this.onTouchStart, this);
|
||||
this.init();
|
||||
},
|
||||
|
||||
registerEvent() {
|
||||
|
||||
},
|
||||
|
||||
init(data) {
|
||||
this.setBoxBounding();
|
||||
this.node.on('touchstart', this.onTouchStart, this);
|
||||
this.initMarKPos(this.nodeTarget.convertToWorldSpaceAR(cc.v2(0, 0)));
|
||||
},
|
||||
|
||||
initMarKPos(posWorld) {
|
||||
let parent = this.node.parent || this.node;
|
||||
let posLocal = parent.convertToNodeSpaceAR(posWorld);
|
||||
this.nodeMark.setPosition(posLocal);
|
||||
let size = this.getMaxLen(this.nodeTarget);
|
||||
this.nodeMark.width = size;
|
||||
this.nodeMark.height = size;
|
||||
posLocal.x -= 0;
|
||||
posLocal.y -= 0;
|
||||
this.nodeMarkBg.setPosition(cc.v2(-posLocal.x, -posLocal.y));
|
||||
},
|
||||
|
||||
getMaxLen(node) {
|
||||
let size = node.width;
|
||||
if (size < node.height) {
|
||||
size = node.height;
|
||||
}
|
||||
return size;
|
||||
},
|
||||
|
||||
/**
|
||||
* 设置触摸区域
|
||||
*/
|
||||
setBoxBounding() {
|
||||
let visiSize = cc.director.getVisibleSize();
|
||||
this.node.width = visiSize.width;
|
||||
this.node.height = visiSize.height;
|
||||
},
|
||||
|
||||
/**
|
||||
* 设置 touch 事件
|
||||
* @param {*} event
|
||||
*/
|
||||
onTouchStart(event) {
|
||||
let touchPos = event.getLocation();
|
||||
console.log('touchPos=', touchPos);
|
||||
let retWorld = this.nodeTarget.getBoundingBoxToWorld();
|
||||
if (retWorld.contains(touchPos)) {
|
||||
this.node._touchListener.setSwallowTouches(false);
|
||||
this.node.active = false;
|
||||
} else {
|
||||
this.node._touchListener.setSwallowTouches(true);
|
||||
}
|
||||
},
|
||||
|
||||
init(data) {
|
||||
|
||||
},
|
||||
|
||||
update(dt) {
|
||||
|
||||
},
|
||||
|
||||
22
GuideDemo/assets/Script/MaskLayer.js
Normal file
22
GuideDemo/assets/Script/MaskLayer.js
Normal file
@@ -0,0 +1,22 @@
|
||||
cc.Class({
|
||||
extends: cc.Component,
|
||||
|
||||
properties: {},
|
||||
|
||||
// LIFE-CYCLE CALLBACKS:
|
||||
|
||||
onLoad() {
|
||||
//获取运行场景的可见大小。
|
||||
let visiSize = cc.director.getVisibleSize();
|
||||
|
||||
this.node.width = visiSize.width;
|
||||
this.node.height = visiSize.height;
|
||||
// this.node.setAnchorPoint(0, 0);
|
||||
this.node.color = cc.hexToColor("#000000");
|
||||
this.node.opacity = 100;
|
||||
},
|
||||
|
||||
start() {},
|
||||
|
||||
// update (dt) {},
|
||||
});
|
||||
9
GuideDemo/assets/Script/MaskLayer.js.meta
Normal file
9
GuideDemo/assets/Script/MaskLayer.js.meta
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"ver": "1.0.5",
|
||||
"uuid": "517f8516-ec12-48f6-8182-bc7aa58636fc",
|
||||
"isPlugin": false,
|
||||
"loadPluginInWeb": true,
|
||||
"loadPluginInNative": true,
|
||||
"loadPluginInEditor": false,
|
||||
"subMetas": {}
|
||||
}
|
||||
Reference in New Issue
Block a user