简单as3动画的模式

时间:2012-06-06 08:52:53

标签: actionscript-3 flash flex animation air

我想在我的照片库中添加功能 - 照片大拇指的不同类型的动画。现在我确实喜欢下面的代码。一切都很好,但我希望拇指从舞台的边缘弹开。

最重要的是,我需要不同的动画模式 - 作为3D旋转木马的动作,旋转成圆形,太阳光线和背部的运动等等。

如果你有这些和类似动画的现成代码,我将非常感激。

[Bindable] private var stageW:int = Capabilities.screenResolutionX;
[Bindable] private var stageH:int = Capabilities.screenResolutionY;

private var itemsVector:Vector.<Image>=new Vector.<Image>();
private var xSpeedVector:Vector.<Number>=new Vector.<Number>();
private var ySpeedVector:Vector.<Number>=new Vector.<Number>();

stage.addEventListener(Event.ENTER_FRAME, update);

private function moveSetup():void {
for(var i:int = 0; i < FlexGlobals.topLevelApplication.objects.length; i++){
    if (FlexGlobals.topLevelApplication.objects[i] is Image){
        var item:Image=FlexGlobals.topLevelApplication.objects[i] as Image;
        item.x=Math.random()*stageW;
        item.y=Math.random()*stageH;
        var randomDirection:Number=Math.random()*2*Math.PI;
        this.addElement(item);
        itemsVector.push(item);
        xSpeedVector.push(2*Math.cos(randomDirection));
        ySpeedVector.push(2*Math.sin(randomDirection));
    }
}   
}

protected function update(event:Event):void {
    for(var i:uint=0;i<itemsVector.length;i++){
        itemsVector[i].x+=xSpeedVector[i];
        itemsVector[i].y+=ySpeedVector[i];
        if(itemsVector[i].x>stageW){
            itemsVector[i].x-=stageW;
        }
        if(itemsVector[i].x<0){
            itemsVector[i].x+=stageW;
        }
        if(itemsVector[i].y>stageH){
            itemsVector[i].y-=stageH;
        }
        if(itemsVector[i].y<0){
            itemsVector[i].y+=stageH;
        }
    }
}

1 个答案:

答案 0 :(得分:1)

看看Greensock's TweenLite library这几乎是Flash中动画的标准(并且,作为一个额外的奖励,最近已经ported to JavaScript)。

它支持各种设置缓动功能,包括反弹功能。该库的付费版本甚至包括创建自定义缓动功能的功能。在我链接到的第一页的中间有一个交互式演示,它允许您现场使用库并测试各种缓动功能。

谷歌搜索将出现各种教程,解释如何构建(伪)3D轨道旋转木马,以及做同样的第三方组件。实际上,通过相当简单的三角测量,这些实现铰链相对简单。 This example似乎为您提供合理的起点以适应您的特定要求。

3D效果当然可以在Flex中实现。我建议你看看Away3D这是一个为Flash平台编写的开源3D库。有一个在Away3D中实现的水平螺旋效果的例子(以及完整的源代码)here

相关问题