继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

关于触摸拖拽

qq_吖小彬彬_0
关注TA
已关注
手记 1
粉丝 0
获赞 16

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);
打开App,阅读手记
3人推荐
发表评论
随时随地看视频慕课网APP

热门评论

as3吗

查看全部评论