egret 示例實戰二:實現愛心縮放和旋轉動畫


1.新建一個TestIndex類,聲明愛心對象

1 private _love;//愛心對象

2.引入要展示的愛心對象

1 //引入愛心對象
2     this._love = CommonFun.creatBitmapByName("love_png");
3     this.addChild(this._love);

3.設置愛心對象居中

1 //設置愛心居中顯示
2     this._love.anchorOffsetX = this._love.width / 2;
3     this._love.anchorOffsetY = this._love.height / 2;
4     this._love.x = Main.instance.width * .5;
5     this._love.y = Main.instance.height * .5;

4.利用Tween動畫設置愛心對象不停縮放

1 //設置愛心縮放顯示
2   egret.Tween.get(this._love,{loop:true}).
3        to({scaleX:0.5,scaleY:0.5},800,egret.Ease.sineIn).
4        to({scaleX:1,scaleY:1},800,egret.Ease.sineOut);

5.利用Tween動畫實現愛心旋轉

1 //設置愛心旋轉顯示
2    egret.Tween.get(this._love,{loop:true}).
3         to({rotation:360},2000,egret.Ease.sineIn);

 

 

6.利用動態幀頻實現愛心旋轉

1 this.addEventListener(egret.Event.ENTER_FRAME,()=>{
2      // console.log('img.rotation = '+img.rotation);
3      img.rotation += 3;
4 },this);

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM