mirror of
https://github.com/Leo501/CocosCreatorTutorial.git
synced 2026-06-07 23:32:46 +08:00
添加一个简单的新手引导时,只能点击某个区域
This commit is contained in:
43
GuideDemo/assets/Script/MarkTouch.js
Normal file
43
GuideDemo/assets/Script/MarkTouch.js
Normal file
@@ -0,0 +1,43 @@
|
||||
cc.Class({
|
||||
extends: cc.Component,
|
||||
|
||||
properties: {
|
||||
nodeTarget: cc.Node,
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
this.registerEvent();
|
||||
this.node.on('touchstart', this.onTouchStart, this);
|
||||
},
|
||||
|
||||
registerEvent() {
|
||||
|
||||
},
|
||||
|
||||
onTouchStart(event) {
|
||||
let touchPos = event.getLocation();
|
||||
console.log('touchPos=', touchPos);
|
||||
let retWorld = this.nodeTarget.getBoundingBoxToWorld();
|
||||
if (retWorld.contains(touchPos)) {
|
||||
this.node._touchListener.setSwallowTouches(false);
|
||||
} else {
|
||||
this.node._touchListener.setSwallowTouches(true);
|
||||
}
|
||||
},
|
||||
|
||||
init(data) {
|
||||
|
||||
},
|
||||
|
||||
update(dt) {
|
||||
|
||||
},
|
||||
|
||||
offEvent() {
|
||||
|
||||
},
|
||||
|
||||
onDestroy() {
|
||||
this.offEvent();
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user