Actionscript 3 AS3滑动手势响应性不强
我来了: 我正在用AS3-AIR做这个移动应用 屏幕中央显示一副扑克牌,使用手指,您可以通过刷卡动作弹开上面的扑克牌以显示下一张扑克牌 这是鸟瞰图,所以只显示一张卡,用户将假定卡组的其余部分在顶卡下方 卡片正面朝下,因此每次用户从屏幕上刷下卡片时,相同的背面图像会一遍又一遍地显示在中间 当用户双击一张卡片的背面时,它会翻转过来,并露出卡片的正面 这是我的代码(我的问题紧跟其后): 以下是我的两个主要问题: -1- 刷卡姿势的反应不是很灵敏:四到五次刷卡中有一次,什么也没发生。我必须做两次刷卡动作,有时甚至更多,才能最终将卡弹掉 我删除了双击侦听器,以防与手势侦听器冲突,问题仍然存在 是不是标准的AS3手势监听器性能不佳 理想情况下,滑动手势应该与TINDER应用程序中的一样:非常灵敏(并带有拖动动作) 除了标准的手势刷解决方案,还有其他选择吗 对我上面的代码有什么建议吗 -2- 如果用户刷卡速度非常快,则会刷掉第二张卡(第一张卡下方),而不是第一张卡。我怎样才能避免呢 非常感谢你的想法,也感谢你的阅读 溴Actionscript 3 AS3滑动手势响应性不强,actionscript-3,swipe,gesture,Actionscript 3,Swipe,Gesture,我来了: 我正在用AS3-AIR做这个移动应用 屏幕中央显示一副扑克牌,使用手指,您可以通过刷卡动作弹开上面的扑克牌以显示下一张扑克牌 这是鸟瞰图,所以只显示一张卡,用户将假定卡组的其余部分在顶卡下方 卡片正面朝下,因此每次用户从屏幕上刷下卡片时,相同的背面图像会一遍又一遍地显示在中间 当用户双击一张卡片的背面时,它会翻转过来,并露出卡片的正面 这是我的代码(我的问题紧跟其后): 以下是我的两个主要问题: -1- 刷卡姿势的反应不是很灵敏:四到五次刷卡中有一次,什么也没发生。我必须做两次刷卡动作
二月十日更新
因此,我听从了马克·诺尔的建议(见下面的答案),使用了鼠标向下&鼠标向上事件处理程序,而不是滑动手势处理程序 结果更好,但并不完美 结果更好,因为鼠标按下时发生的拖动解决了第二张卡飞出屏幕的问题 结果并不完美,因为鼠标按下/鼠标按下事件与双击事件之间存在冲突:当我双击一张卡时,两次点击都被检测为卡的两次微拖动,但也被检测为双击动作 因此,我做了以下工作:
- 要使卡片朝屏幕边缘清晰而大的拖动,松开鼠标/手指时,卡片将从屏幕上剪下
- 对于卡的小阻力,将卡夹回其原始位置。这样,在卡被双击的情况下,翻转将从卡的原始位置发生
backBlue1.addEventListener(MouseEvent.MOUSE\u DOWN,mouseDownHandler);
backBlue2.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownHandler);
backBlue1.addEventListener(MouseEvent.MOUSE\u UP,mouseHandler);
backBlue2.addEventListener(MouseEvent.MOUSE\u UP,mouseHandler);
backBlue1.addEventListener(MouseeEvent.双击,cardFlipper);
Backblue 2.addEventListener(MouseeEvent.双击,cardFlipper);
函数mouseDownHandler(e:MouseEvent):void
{
e、 target.startDrag();
}
函数MouseHandler(e:MouseEvent):void
{
e、 target.stopDrag();
ecartX=initialX2-e.target.x;//ecartX是最终卡位置与原始卡位置的距离。
如果(Math.abs(ecartX)limitX)//长时间拖动,则该卡将从屏幕上剪下
{
//向左滑动
如果(ecartX>0)
{
randomX=Math.floor(Math.random()*(randomMaxX-randomMinX+1))+randomMinX;
}
//向右滑动
如果(ecartX<0)
{
randomX=数学地板(Math.random()*(randomMaxX2-randomMinX2+1))+randomMinX2;
}
randomY=Math.floor(Math.random()*(randomMaxY-randomMinRotation+1))+randomMinY;
randomRotation=Math.floor(Math.random()*(randomMaxRotation-randomMinRotation+1))+randomMinRotation;
var tl15=新的TimelineMax();
tl15.添加标签(“屏幕上的卡片”);
如果(e.target==backBlue1)
{
tl15.to(e.target,1,{y:randomY,x:randomX,rotation:randomRotation,ease:Circ.easeOut});
tl15.to(backBlue2,0,{y:initialY2,x:initialX2,旋转:0,ease:Linear.easeNone},“-=1”);
tl15.添加标签(“屏幕外卡片”,“-=0.5”);
tl15.addCallback(播放幻灯片,“屏幕上的卡片”);
tl15.addCallback(互换,“屏幕外的卡片”);
}
如果(e.target==backBlue2)
{
tl15.to(e.target,1,{y:randomY,x:randomX,rotation:randomRotation,ease:Circ.easeOut});
tl15.to(backBlue1,0,{y:initialY2,x:initialX2,旋转:0,ease:Linear.easeNone},“-=1”);
tl15.添加标签(“屏幕外卡片”,“-=0.5”);
tl15.addCallback(播放幻灯片,“屏幕上的卡片”);
tl15.addCallback(互换,“屏幕外的卡片”);
}
}
}
公共功能卡片翻页器(e:MouseeEvent)
{
//...
}
//Adding three same backs of cards to the stage:
addChild(backBlue3); //No event listener will be attached to this card
addChild(backBlue2);
addChild(backBlue1);
//backBlue1 and backBlue2 will alternate their Indexes/depths to create the illusion of an infinite deck of cards. So, when backBlue1 is thrown out of the screen, backBlue2 immediately fills the center of screen.
Multitouch.inputMode = MultitouchInputMode.GESTURE;
backBlue1.addEventListener(TransformGestureEvent.GESTURE_SWIPE, backCard_handler_swipe);
backBlue2.addEventListener(TransformGestureEvent.GESTURE_SWIPE, backCard_handler_swipe);
backBlue1.addEventListener(MouseEvent.DOUBLE_CLICK, cardFlipper);
backBlue2.addEventListener(MouseEvent.DOUBLE_CLICK, cardFlipper);
public function backCard_handler_swipe(e:TransformGestureEvent):void
{
//*********************************** Setting the random positions for swiped off cards ***********************************
//Swipe is done towards the left
if (e.offsetX == -1)
{
randomX = Math.floor(Math.random() * (randomMaxX - randomMinX + 1)) + randomMinX;
}
//Swipe is done towards the right
if (e.offsetX == 1)
{
randomX = Math.floor(Math.random() * (randomMaxX2 - randomMinX2 + 1)) + randomMinX2;
}
randomY = Math.floor(Math.random() * (randomMaxY - randomMinRotation + 1)) + randomMinY;
randomRotation = Math.floor(Math.random() * (randomMaxRotation - randomMinRotation + 1)) + randomMinRotation;
//*********************************** Creating a GreenSock TimeLineMax timeline to tween the "ejected" card ***********************************
var tl15 = new TimelineMax();
tl15.addLabel("cardOnScreen"); //At this point of the Timeline (the very beginning), a "Swiping sound" will be played.
if (e.target == backBlue1)
{
//backBlue1 is tweened off the screen
tl15.to(e.target, 1, {y:randomY, x:randomX, rotation:randomRotation, ease:Circ.easeOut});
//backBlue2 is instantly placed in the center of the screen, behind backBlue1
tl15.to(backBlue2, 0, {y:initialY2, x:initialX2, rotation:0, ease:Linear.easeNone}, "-=1");
tl15.addLabel("cardOffScreen", "-=0.5"); //The exact middle of the backBlue1 tween animation
tl15.addCallback(playSlide, "cardOnScreen"); //Playing the "Swiping Sound".
tl15.addCallback(swapingBacks, "cardOffScreen"); //swapingBacks function is called to place backBlue2 on top of backBlue1
}
if (e.target == backBlue2)
{
tl15.to(e.target, 1, {y:randomY, x:randomX, rotation:randomRotation, ease:Circ.easeOut});
tl15.to(backBlue1, 0, {y:initialY2, x:initialX2, rotation:0, ease:Linear.easeNone}, "-=1");
tl15.addLabel("cardOffScreen", "-=0.5");
tl15.addCallback(playSlide, "cardOnScreen");
tl15.addCallback(swapingBacks, "cardOffScreen");
}
}
public function swapingBacks()
{
swapChildren(backBlue1, backBlue2);
}
public function cardFlipper(e:MouseEvent)
{
//Flipping of the card is working fine
}
backBlue1.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
backBlue2.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
backBlue1.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
backBlue2.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler);
backBlue1.addEventListener(MouseEvent.DOUBLE_CLICK, cardFlipper);
backBlue2.addEventListener(MouseEvent.DOUBLE_CLICK, cardFlipper);
function mouseDownHandler(e:MouseEvent):void
{
e.target.startDrag();
}
function mouseUpHandler(e:MouseEvent):void
{
e.target.stopDrag();
ecartX = initialX2 - e.target.x; //ecartX is the distance of the final card position with the original one.
if (Math.abs(ecartX) < limitX) //For a very small drag, the card is tweened back to its initial place
{
var tl25 = new TimelineMax();
tl25.to(e.target, 0.5, {y:initialY2, x:initialX2, rotation:0, ease:Linear.easeNone}, "-=0");
}
if (Math.abs(ecartX) > limitX) //For a clear long drag, the card is tweened off the screen
{
//Swipe to the left
if (ecartX > 0)
{
randomX = Math.floor(Math.random() * (randomMaxX - randomMinX + 1)) + randomMinX;
}
//Swipe to the right
if (ecartX < 0)
{
randomX = Math.floor(Math.random() * (randomMaxX2 - randomMinX2 + 1)) + randomMinX2;
}
randomY = Math.floor(Math.random() * (randomMaxY - randomMinRotation + 1)) + randomMinY;
randomRotation = Math.floor(Math.random() * (randomMaxRotation - randomMinRotation + 1)) + randomMinRotation;
var tl15 = new TimelineMax();
tl15.addLabel("cardOnScreen");
if (e.target == backBlue1)
{
tl15.to(e.target, 1, {y:randomY, x:randomX, rotation:randomRotation, ease:Circ.easeOut});
tl15.to(backBlue2, 0, {y:initialY2, x:initialX2, rotation:0, ease:Linear.easeNone}, "-=1");
tl15.addLabel("cardOffScreen", "-=0.5");
tl15.addCallback(playSlide, "cardOnScreen");
tl15.addCallback(swapingBacks, "cardOffScreen");
}
if (e.target == backBlue2)
{
tl15.to(e.target, 1, {y:randomY, x:randomX, rotation:randomRotation, ease:Circ.easeOut});
tl15.to(backBlue1, 0, {y:initialY2, x:initialX2, rotation:0, ease:Linear.easeNone}, "-=1");
tl15.addLabel("cardOffScreen", "-=0.5");
tl15.addCallback(playSlide, "cardOnScreen");
tl15.addCallback(swapingBacks, "cardOffScreen");
}
}
}
public function cardFlipper(e:MouseEvent)
{
//...
}