Контроль временной шкалы с помощью pinchzoom в Actionscript 3.0 - PullRequest
0 голосов
/ 26 апреля 2018

Я использую Actionscript 3.0 во Flash. Есть ли способ контролировать временную шкалу с помощью зажима (поэтому вместо уменьшения масштаба вы перемещаете временную шкалу вперед / назад)? Я работаю над приложением истории, где игрок контролирует историю.

1 Ответ

0 голосов
/ 26 апреля 2018

Вы можете сделать что-то вроде следующего:

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);
}
...