用于实现H5中不规则图形按钮可点击区域的判断。
ShapeTouch 该Javascript库用于实现H5中不规则图形按钮可点击区域的判断,特别用于H5游戏中的某些场景
This Library used for testing the alpha value of a pixel on the irregular image, for example, the irregular button touch on the H5Game.
有问题可联系QQ:46194470
king.shape.touch(src,x,y,callback) king.shape.touchPoint(src,point,callback)
point对象示例:
The point object like this:
{x:9,y:25} Return 返回值
Object {touch: true, alpha: 255} Or Object {touch: false, alpha: 0}
touch为true时,该点非透明,点击生效,alpha值大于0,touch为false时,该点透明,alpha为0.
(开发者也可以根据alpha的值自行判断点击是否生效)
The touch is true, the point is not transparent, the alpha value is greater than 0.
Html:添加引用后直接使用
<script type="text/javascript" src="ShapeTouch-min.js"></script> <script type="text/javascript"> (function() { king.shape.touch('images/logo.png',20,40,function(result){ console.log(result); }); }); </script>
Cocos creator:将文件放入assets即可,不需require
this.node.on('touchend', function (event) { var touchPoint = event.getLocation(); var node = event.currentTarget; var nodePoint = node.convertToNodeSpace(touchPoint); var nodeSrc = node.getComponent(cc.Sprite).spriteFrame.getTexture().url; king.shape.touchPoint(nodeSrc,nodePoint,function(result){ console.log(result); }); }, this);
版权声明:
1、该文章(资料)来源于互联网公开信息,我方只是对该内容做点评,所分享的下载地址为原作者公开地址。2、网站不提供资料下载,如需下载请到原作者页面进行下载。