egret学习日记4

来源:互联网 发布:阿里云域名证书 编辑:程序博客网 时间:2024/06/07 01:12

缓动动画:

基本的缓动:egret提供缓动库,使用Tween.get()方法来获得缓动目标。然后可以对其任意可写的属性进行缓动控制。

 egret.Tween.get( this._bird ).to( {x:loc.x,y:loc.y}, 300, egret.Ease.sineIn );

缓动产生的事件:缓动是由一系列中间状态按顺序变化形成的,每一个中间状态可以产生一个更新事
  件,便于完成更丰富的功能,在Tween.get()的第二个参数,即属性集
合参数中可以定义更新事件。属性集合是一个键值对集合,将更新事件分配给on
 Change键即可,如事件有其作用域要求,可以同时将作用域引用分配给on
ChangeObj键。

 var funcChange = ():void=>{
            this._bird.rotation += 6 * iDirection;
        }
        var iDirection:number = Math.random() > .5 ? -1 : 1;    /// 随机方向
        egret.Tween.get( this._bird, { onChange:funcChange, onChangeObj:this } )
            .to( {x:loc.x,y:loc.y}, 300, egret.Ease.sineIn );

缓动过程方程:egret提供的缓动方程在egret.Ease中

var params:EaseFunc = this._vcEaseFunc[ ++this._idxEase % this._vcEaseFunc.length ];
        egret.Tween.get( this._bird )
            .to( {x:loc.x,y:loc.y}, 600, params.func );

复合缓动:复合动画是Tween的重要特色。
不同的动画可以按照顺序通过链式调用依次连接循环调用。
 每次缓动调用结束时可以通过Tween.call()来进行该阶段的完成事件
  处理。
不同的缓动之间可以通过Tween.wait()来控制延迟时间。
 按照本示例所示,开发者可以使用egret.Tween创建各种丰富而灵活的
动画组合。

 egret.Tween.get( this._bird, { loop:true} )
            .to( {x:this._vcLocation[0].x, y:this._vcLocation[0].y}, 500 )
                .call( ()=>{ this._bird.rotation = 180 - this._rotCommon;  } ).wait( 200 )
            .to( {x:this._vcLocation[1].x, y:this._vcLocation[1].y}, 500 )
                .call( ()=>{ this._bird.rotation = - 90; } ).wait( 200 )
            .to( {x:this._vcLocation[2].x, y:this._vcLocation[2].y}, 500 )
                .call( ()=>{ this._bird.rotation = this._rotCommon; } ).wait( 200 )
            .to( {x:this._vcLocation[3].x, y:this._vcLocation[3].y}, 500 )
                .call( ()=>{ this._bird.rotation = - 90; } ).wait( 200 );