【cocos2d-js 学习分享 六】再说触摸相应
发布时间:2020-12-14 19:52:22 所属栏目:百科 来源:网络整理
导读:今天在写cocos2dx-js代码时发现一个问题 就是在onTouchBegan(touch,event) { }里面使用this.removeChild()时发生错误 //原因是cocosjs与c++ cocos之间存在差异 //触摸开始 onTouchBegan:function (touch,event) { var _size =cc.director.getWinSize(); var
今天在写cocos2dx-js代码时发现一个问题 就是在onTouchBegan(touch,event) {
}里面使用this.removeChild()时发生错误 //原因是cocosjs与c++ cocos之间存在差异 //触摸开始 onTouchBegan:function (touch,event) { var _size =cc.director.getWinSize(); var point=touch.getLocation(); var rect=cc.rect(_size.width/2-30,_size.height/2-30,60,60); if (cc.rectContainsPoint(rect,point)) { //this.removeChild(this.tip,true); var asd = cc.director.getRunningScene().getChildByTag(1000); asd.removeChild(asd.tip); asd.removeChild(asd.clip); //this.removeChild(clip); //this.removeChild(this.tip); //this.removeChild(this.clip); //removeAllChildren(); return true; } return false; }, 上述注释的部分为错误用法; //我们无法再onTouchBegan中使用this引用。所以我们需要使用总管来获取我们当前场景中的当前层 cc.director.getRunningScene().getChildByTag(); 来获取当前层,得到当前层以后我们就可以获取当前层的属性了 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |