点击事件:hittest

流程:
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);
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容