【问题标题】:Control timeline with pinchzoom in Actionscript 3.0在 Actionscript 3.0 中使用 pinchzoom 控制时间线
【发布时间】:2018-10-07 14:22:06
【问题描述】:

我在 Flash 中使用 Actionscript 3.0。有没有办法通过捏合来控制时间线(所以不是缩小/缩小,而是前后移动时间线)?我正在开发一个故事应用程序,玩家可以控制故事。

【问题讨论】:

  • 是的。到目前为止,您尝试/研究了什么?

标签: actionscript-3 flash pinchzoom


【解决方案1】:

您可以执行以下操作:

import flash.events.TransformGestureEvent;
Multitouch.inputMode = MultitouchInputMode.GESTURE;

stop();

//listen on whatever object you want to be able zoom on
stage.addEventListener(TransformGestureEvent.GESTURE_ZOOM , zoomGestureHandler); 

function zoomGestureHandler(e:TransformGestureEvent):void{
    //get the zoom amount (since the last event fired)
    //we average the two dimensions (x/y). 1 would mean no change,  .5 would be half the size as before, 2 would twice the size etc.
    var scaleAmount:Number = (e.scaleX + e.scaleY) * 0.5;

    //set the value (how many frames) to skip ahead/back
    //we want the value to be at least 1, so we use Math.max - which returns whichever value is hight
    //we need a whole number, so we use Math.round to round the value of scaleAmount
    //I'm multiplying scaleAmount by 1.25 to make the output potentially go a bit higher, tweak that until you get a good feel.
    var val:int = Math.max(1, Math.round(scaleAmount * 1.25));

    //determine if the zoom is actually backwards (smaller than before)
    if(scaleAmount < 1){
        val *= -1;  //times the value by -1 to make it a negative number
    }

    //now assign val to the actual target frame
    val = this.currentFrame + val;

    //check if the target frame is out of range (less than 0 or more than the total)
    if(val < 1) val = this.totalFrames + val; //if less than one, add (the negative number) to the totalFrames value to loop backwards
    if(val > this.totalFrames) val = val - this.totalFrames; //if more than total, loop back to the start by the difference

    //OR
    if(val < 1) val = 0; //hard stop at the first frame (don't loop)
    if(val > this.totalFrames) val = this.totalFrames; //hard stop at the last frame (don't loop)

    //now move the playhead to the desired frame
    gotoAndStop(val);
}

【讨论】:

  • 像魅力一样工作!谢谢!
  • 很抱歉,对此还是很陌生。试图找到一种方法使时间线速度跟随您所说的手势速度,但我无法弄清楚。如果您能再次帮助我,我将不胜感激。
  • 如果这有助于您解决问题,请接受答案。
猜你喜欢
  • 2011-01-21
  • 1970-01-01
  • 2017-09-05
  • 2017-05-03
  • 2013-12-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多