zoukankan      html  css  js  c++  java
  • TweenAccessor,Tween,OriginalTween,BaseTween,Timeline

    TweenAccessor设置初始值和目标值的接口
    Tween:在初始值和目标值之间做动画补充
    OriginalTween:动画的帧计算类
    BaseTween:一个抽象类,有一个类似Activity的生命过程:开始-暂停-结束。
    Timeline:一个实现BaseTween抽象类的类。这个类可以实现多个多个对象的连续动画。

     1 public class ActorListener implements ApplicationListener{
     2     private Stage mStage;
     3     private Texture texture;
     4     private ActorView mActorView;
     5     public ActorListener() {
     6 
     7     }
     8     @Override
     9     public void create() {
    10       mStage =new Stage(240, 400, true);
    11       //早View中画一张图片
    12       mActorView =new ActorView("image");
    13       texture =new Texture(Gdx.files.internal("flower.jpg"));
    14       mActorView.region =new TextureRegion(texture,0,0,64,64);
    15       mActorView.setSize(64, 64);
    16       mStage.addActor(mActorView);
    17      //将ActorView.class这个对象的处理类ActorAccessor的对象Push到Map中
    18      Tween.registerAccessor(ActorView.class, new ActorAccessor());
    19       //设置动画需要变换的值,有X,Y坐标,颜色等
    20        Tween.to(mActorView, ActorAccessor.POS_XY, 1.0f)
    21        //设置动画效果
    22        .ease(Bounce.INOUT)
    23        //设置坐标的目标值
    24         .target(200, 300)
    25         //把这个动画放到tweenManager中,真正启动动画是在render中
    26         .start(ActorAccessor.tweenManager);
    27     }
    28     @Override
    29     public void render() {
    30         Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); 
    31         ActorAccessor.tweenManager.update(Gdx.graphics.getRawDeltaTime());
    32         mStage.act(Gdx.graphics.getDeltaTime());
    33         mStage.draw();
    34         
    35     }
    36 }

    Timeline 实现多个连续的动画。
    //同一个对象在不同的时间段内实现一组连续的动画。
    Timeline.createSequence();
    下面这段代码实现分别在每秒中移动到某个坐标

     1 public class ActorListener implements ApplicationListener{
     2     private Stage mStage;
     3     private Texture texture;
     4     private ActorView mActorView;
     5     private Timeline mTimeline;
     6     public ActorListener() {
     7 
     8     }
     9     @Override
    10     public void create() {
    11       mStage =new Stage(240, 400, true);
    12       mActorView =new ActorView("image");
    13       texture =new Texture(Gdx.files.internal("flower.jpg"));
    14       mActorView.region =new TextureRegion(texture,0,0,64,64);
    15       mActorView.setSize(64, 64);
    16       mStage.addActor(mActorView);
    17       Tween.registerAccessor(ActorView.class, new ActorAccessor());
    18       //创建一个Timeline对象,这个对象是一个动画的集合
    19       mTimeline = Timeline.createSequence();
    20     
    21       mTimeline.push(Tween.to(mActorView, ActorAccessor.POS_XY, 1.0f).target(200, 300, 0).ease(Bounce.INOUT));
    22       mTimeline.push(Tween.to(mActorView, ActorAccessor.POS_XY, 1.0f).target(100, 200, 0).ease(Bounce.INOUT));
    23       mTimeline.push(Tween.to(mActorView, ActorAccessor.POS_XY, 1.0f).target(20, 30, 0).ease(Bounce.OUT)) .start(ActorAccessor.tweenManager);
    24 
    25     }
    26     @Override
    27     public void render() {
    28         Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); 
    29         //开始更新动画
    30         ActorAccessor.tweenManager.update(Gdx.graphics.getRawDeltaTime());
    31         mStage.act(Gdx.graphics.getDeltaTime());
    32         mStage.draw();
    33         
    34     }
    35 }

    //在相同的时间段内实现各种动画,比如一边移动一边旋转一边放大缩小
    Timeline.createParallel();
    下面这段代码实现在同一秒内,在移动的过程中不断的缩小图片

    BaseTween抽象类的类。这个类可以实现多个多个对象的连续动画。

     1 public class ActorListener implements ApplicationListener{
     2     private Stage mStage;
     3     private Texture texture;
     4     private ActorView mActorView;
     5     private Timeline mTimeline;
     6     public ActorListener() {
     7 
     8     }
     9     @Override
    10     public void create() {
    11       mStage =new Stage(240, 400, true);
    12       mActorView =new ActorView("image");
    13       texture =new Texture(Gdx.files.internal("flower.jpg"));
    14       mActorView.region =new TextureRegion(texture,0,0,64,64);
    15       mActorView.setSize(64, 64);
    16       mStage.addActor(mActorView);
    17       Tween.registerAccessor(ActorView.class, new ActorAccessor());
    18       //创建一个Timeline对象,这个对象是一个动画的集合
    19       mTimeline = Timeline.createSequence();
    20     
    21       mTimeline.push(Tween.to(mActorView, ActorAccessor.SCALE_XY, 1.0f).target((float)0.5,(float) 0.5, 0).ease(Cubic.OUT).delay((float)0.3));
    22       mTimeline.push(Tween.to(mActorView, ActorAccessor.POS_XY, 1.0f).target(200, 300, 0).ease(Cubic.OUT)) .start(ActorAccessor.tweenManager);
    23 
    24     }
    25     @Override
    26     public void render() {
    27         Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); 
    28         //开始更新动画
    29         ActorAccessor.tweenManager.update(Gdx.graphics.getRawDeltaTime());
    30         mStage.act(Gdx.graphics.getDeltaTime());
    31         mStage.draw();
    32         
    33     }
    34 }
  • 相关阅读:
    [Flutter] 转一个Flutter学习思维导图
    [Node.js] TypeScript 实现 sleep 函数
    [Docker] Win10中安装Docker并运行Nginx镜像
    [Zabbix] 安装MySQL5.7, 部署Zabbix到CentOS 7日记
    [Delphi]无边框窗口最大化不挡任务栏方法
    [Flutter] 一些面试可能会问基础知识
    Flutter main future mirotask 的执行顺序
    Underscore.js基础入门
    将第三方包安装到maven本地仓库
    Ubuntu下JDK1.8安装后配置环境变量
  • 原文地址:https://www.cnblogs.com/mogul/p/3008353.html
Copyright © 2011-2022 走看看