美文网首页
点击事件:hittest

点击事件:hittest

作者: 龙叉叉 | 来源:发表于2019-02-25 11:46 被阅读0次

    流程:
    1、层级管理器中,添加点触区域
    2、预设控制脚本,

        properties: {
            collider: {
                default: null,
                type: cc.PolygonCollider
            },
            title: {
                default: null,
                type: cc.Label
            }
        },
    
    

    3、onLoad启动:

    //启动碰撞控制:
            cc.director.getCollisionManager().enabled = true;
    //启动碰撞边缘显示:
            cc.director.getCollisionManager().enabledDebugDraw = true;
    //监听触动事件
            this.node.on(cc.Node.EventType.TOUCH_START, function (touch, event) {
                var touchLoc = touch.getLocation(); 
    //点触事件发生时,判断是否在区域内,并提示           
                if (cc.Intersection.pointInPolygon(touchLoc, this.collider.world.points)) {
                    this.title.string = 'Hit';
                }
                else {
                    this.title.string = 'Not hit';
                }
            }, this);
    

    相关文章

      网友评论

          本文标题:点击事件:hittest

          本文链接:https://www.haomeiwen.com/subject/itvwyqtx.html