从当前位置推进,Tweener,AS3

时间:2010-03-17 15:43:50

标签: flash actionscript-3 tweener

我希望我的动画每次前进120像素。相反,我的动画会回到底部,而不是从它的新位置前进。它假设一个新的位置,但总是先回到底部。 如何让我的动画每次从当前位置前进?

目标
我希望我的动画从当前新位置前进120像素,并在十点后重复。

问题
在进行之前,动画每次都会重置到底部。我不知道如果它是一个Tweener问题,我如何设置我的循环,或者不相关的东西。如果您能给我一个如何修改此代码的示例,我将不胜感激。

alt text http://www.ashcraftband.com/myspace/videodnd/tweener.jpg

NumbersView.as'代码可以工作,但是按照'

描述的方式搞错了
package   
{ 
    import flash.display.DisplayObject; 
    import flash.display.MovieClip; 
    import flash.utils.Dictionary; 
    import flash.events.Event; 
    import caurina.transitions.Tweener; 

    public class NumbersView extends MovieClip 
    { 
        private var _listItems:Array; 
        private var previousNums:Array; 
        private const numHeight:int = 120; 

        public function NumbersView()  
        { 
            _listItems = new Array(); 
            previousNums = new Array(); 
            //Tweener.init();

            var item:NumberImage; 
            for (var i:Number = 0; i < 9; i++) { 
                item = new NumberImage(); 
                addChild(item); 
                item.x = i * item.width; 
                _listItems.push(item); 
            } 
        } 

        public function setTime($number:String):void { 
            var nums:Array = $number.split(""); 
            //trace("$number = " + $number);
            for (var i:Number = 0; i < nums.length; i++) { 
                if (nums[i] == previousNums[i]) continue; 
                Tweener.removeTweens(_listItems[i]);    

                //newY:int = -numHeight;
                var newY:int = int(nums[i]) * -numHeight;
                trace("newY = " + newY);
                trace("currY = " + _listItems[i].y);                
                if (_listItems[i].y < 0) _listItems[i].y = numHeight; 
                Tweener.addTween(_listItems[i], { y:newY, time:3 } ); 
            } 
            previousNums = nums; 
        } 
    } 
} 

alt text http://www.ashcraftband.com/myspace/videodnd/tweener_.jpg

中间人 http://hosted.zeh.com.br/tweener/docs/en-us/

1 个答案:

答案 0 :(得分:0)

我能够让你的代码动画项目,我看到每次动画项目重新启动到他们的位置,这是我改变的方式,让他们从当前位置向上移动:

原:

if (_listItems[i].y < 0) _listItems[i].y = numHeight;
Tweener.addTween(_listItems[i], { y:newY, time:3 } ); 

更改为:

//if (_listItems[i].y < 0) _listItems[i].y = numHeight; //get rid of this line
Tweener.addTween(_listItems[i], { y:_listItems[i].y+newY, time:3 } ); 

对于循环部分,你可以使用一个计时器,这是我作为一个例子放在一起的你。它可能并不完美,但希望能让您了解自己想要做什么:

package   
{ 
    import flash.display.DisplayObject; 
    import flash.display.MovieClip; 
    import flash.utils.Dictionary; 
    import flash.events.Event; 
    import flash.events.TimerEvent;
    import caurina.transitions.Tweener; 
    import flash.utils.Timer;

public class NumbersView extends MovieClip 
{ 
    private var _listItems:Array; 
    private var previousNums:Array; 
    private const numHeight:int = 120; 
    var t:Timer;

    public function NumbersView()  
    { 
        _listItems = new Array(); 
        previousNums = new Array(); 
        //Tweener.init();

        var item:NumberImage; 
        for (var i:Number = 0; i < 9; i++) { 
            item = new NumberImage(); 
            addChild(item); 
            item.x = i * item.width; 
            _listItems.push(item); 
        }

        t = new Timer( 1000 ) //1000ms = 1 second intervals
        t.addEventListener(TimerEvent.TIMER, onTimer);
        t.start();

    } 

    public function onTimer( e:TimerEvent):void {

        //this will run every 10th time firing
        if( t.currentCount % 10 == 0 ) {
            //do something to reset the listItems
            for (var i:Number = 0; i < _listItems.length; i++) { 
                _listItems[i].y = numHeight;
            }
        }

        //do your setTime function, I just randomly called it with random numbers
        setTime(Math.round(Math.random()*234567).toString());
    }

    public function setTime(number:String):void { 
        var nums:Array = number.split(""); 
        trace("$number = " + number);
        for (var i:Number = 0; i < nums.length; i++) { 
            if (nums[i] == previousNums[i]) continue; 
            Tweener.removeTweens(_listItems[i]);    

            //newY:int = -numHeight;
            var newY:int = int(nums[i]) * -numHeight;
            trace("newY = " + newY);
            trace("currY = " + _listItems[i].y);                

            Tweener.addTween(_listItems[i], { y:_listItems[i].y+newY, time:3 } ); 
        } 
        previousNums = nums; 
    } 
} 
}