开发者

problem with tweenlite

i have a bit of a problem. i have the following function:

private function elementsLoadedHandler(e:Event):void
        {
            elementContainer=new Sprite();
            var currentItem:uint;
            for (var i:uint=0; i < numberItems; i++)
            {
                var element:Element=new Element(elementModel.elements[currentItem]);
                element.x=xPos;
                element.alpha=.5;
                addChild(element);
                xPos+=130;
                currentItem++;
                elementsArr.push(element);
                if (currentItem >= elementModel.elements.length)
                {
                    currentItem == 0;
                }
            }
            movementTimer=new Timer(_movementSpeed, 0);
            movementTimer.addEventListener(TimerEvent.TIMER, moveItems);
            movementTimer.start();
            layout();
        }

What this basicly does is place elements from an array onto the stage next to eachother. Now i want them to move to the right together. i do this as following:

private function moveItems(e:TimerEvent):void
        {
        开发者_高级运维    var alphaVal:Number=.5;
            movementTimer.delay+=25;
            for (var i:uint=0; i < elementsArr.length; i++)
            {
                xPos=elementsArr[i].x + 130;
                TweenLite.to(elementsArr[i], .5, {x: "130"});
                if (elementsArr[i].x > _width)
                {
                    elementsArr[i].x=0;
                }
            }
        }

So i'm moving the items to the right and then i check if the last item is outside of the stage, if so i reset its position to 0 so it goes back to the left and this way i have a continious loop of items moving to the right. The problem is that the way i do it, i have 11 tweens being executed per second, wich makes it laggy. I was thinking about putting the items in an container and tweening the container but i dont seem to be getting a nice continious flow then. Does anyone know how to solve this?

Also, in the first function you can see that i'm doing a for loop. the numberItems variable represents 11, but the amount of items in elementModel.elements is only 6, so for the other 5 elements i just pick the first 5 items from the array again. The problem is that when i trace these items it gives me 0. How can i take items from an array multiple times without overwriting the previous version of it?


You don't need to use tween lite for this. All you need to do in the moveItems function is move each item a little (elemtsArr[i].x += 5, for example) and if elementsArr[i].x > _width, then replace it a 0.

Something like this should work:

function moveItems( e:TimerEvent ):void
{
    for (var i:int = 0; i < elemntsArr.length; i++)
    {
        elementsArr[i].x += 5;
        if (elementsArr[i].x > _width)
            elementsArr[i].x = 0;
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜