首先放上预览地址:http://annie.wxbuluo.com/multiTouch/
官网的有一个双指旋转缩放的demo,这个是在那个demo的基础上加了个双指移动的功能,下面贴一下主要代码
var start1 = start2 = {};
s.addEventListener(annie.Event.ADD_TO_STAGE,function (e) {
s.stage.isMultiTouch=true;
s.stage.addEventListener(annie.TouchEvent.ON_MULTI_TOUCH,function (evt) {
if(start1.x){
var end1 = {x:evt.clientPoint1.x,y:evt.clientPoint1.y};
var end2 = {x:evt.clientPoint2.x,y:evt.clientPoint2.y};
res1 = (end1.x-start1.x)*(end2.x-start2.x);
res2 = (end1.y - start1.y)*(end2.y - start2.y);
if(res1<1000 || res2<1000){
if(res1>0 || res2>0){
var offsetX = end1.x - start1.x;
var offsetY = end1.y - start1.y;
if(offsetX<10 && offsetX>-10){
s.test_mc.x += offsetX*5;
}
if(offsetY<10 && offsetY>-10){
s.test_mc.y += offsetY*5;
}
}
if(res1<=0 || res2<=0){
s.test_mc.rotation+=evt.rotate;
s.test_mc.scaleY+=evt.scale;
s.test_mc.scaleX+=evt.scale;
}
}
}
start1 = {x:evt.clientPoint1.x,y:evt.clientPoint1.y};
start2 = {x:evt.clientPoint2.x,y:evt.clientPoint2.y};
});
});
最后放上github地址:https://github.com/ningbnii/annie_demo
QQ:296720094 有问题大家可以一起交流
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!