手记

关于触摸拖拽

var Touchlistener = cc.EventListener.create({
event: cc.EventListener.TOUCH_ONE_BY_ONE,
swallowTouches: true,
onTouchBegan: function (touch, event) {
var target = event.getCurrentTarget();
var locationInNode = target.convertToNodeSpace(touch.getLocation());
var s = target.getContentSize();
var rect = cc.rect(0, 0, s.width, s.height);
if (cc.rectContainsPoint(rect, locationInNode)) {
return true;
}
return false;
},
onTouchMoved: function (touch, event) {

            var target = event.getCurrentTarget();
            var delta = touch.getDelta();
            target.x += delta.x;
            target.y += delta.y;
            if(target.x<0){
                target.x=0;
            }else if(target.x>1920){
                target.x=1920;
            }

            if(target.y<0){
                target.y=0;
            }else if(target.y>1080){
                target.y=1080;
            }

        },
        onTouchEnded: function (touch, event) {
            var target = event.getCurrentTarget();
            var lidhit = lid_png.getBoundingBox();
           // var funchinebt_pnghit = funchinebt_png.getBoundingBox();

                if (cc.rectIntersectsRect(lidhit, alum_pnghit)) {
                    cc.log("1");
                    hitcap = false;
                } else {
                    hitcap = true;
                    cc.log("2");
                }
            }
        }
    });
    cc.eventManager.addListener(Touchlistener,lid_png);
3人推荐
随时随地看视频
慕课网APP

热门评论

as3吗

查看全部评论