King.ShapeTouch實(shí)現(xiàn)H5中區(qū)域判斷
ShapeTouch
ShapeTouch 該Javascript庫用于實(shí)現(xiàn)H5中不規(guī)則圖形按鈕可點(diǎn)擊區(qū)域的判斷,特別用于H5游戲中的某些場景。
API 調(diào)用接口
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時,該點(diǎn)非透明,點(diǎn)擊生效,alpha值大于0,touch為false時,該點(diǎn)透明,alpha為0.
(開發(fā)者也可以根據(jù)alpha的值自行判斷點(diǎn)擊是否生效)
The touch is true, the point is not transparent, the alpha value is greater than 0.
Use 使用
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);評論
圖片
表情
