闺蜜头像一对三张动漫:java

来源:百度文库 编辑:九乡新闻网 时间:2024/05/01 01:45:34

java-universal-tween-engine,一个动画系统库

    博客分类:
  • android
JavaAndroidGoogleSwingOShttp://code.google.com/p/java-universal-tween-engine/

可以用来创建平滑的移动系统,比如循环,移动,旋转等。由于项目使用纯java写成,所以支持swt,swing,android,opengles等。Tween缓冲大家应该都不陌生,说白了就是从一起始位置逐渐移动到目标位置的过程,这个过程可以是加速移动,也可以是减速移动,这些不同的缓动方式就是Tween的各种ease。

源码在最后,将其解压后复制到src就可以了。

用法,先定义一个需要运动的物体:
Java代码  
  1. public class Particule {   
  2.     private float x, y;   
  3.        
  4.     public float getX() {   
  5.             return x;   
  6.     }   
  7.        
  8.     public float getY() {   
  9.             return y;   
  10.     }   
  11.        
  12.     public void setX(float x) {   
  13.             this.x = x;   
  14.     }   
  15.        
  16.     public void setY(float y) {   
  17.             this.y = y;   
  18.     }   
  19. }  


然后,实现Tweenable接口,用于表明运动的返回值和变化值
Java代码  
  1. import aurelienribon.tweenengine.Tweenable;   
  2.   
  3. public class TweenableParticule implements Tweenable {   
  4.     // The following lines define the different possible tween types.   
  5.     // It's up to you to define what you need :-)   
  6.   
  7.     public static final int X = 1;   
  8.     public static final int Y = 2;   
  9.     public static final int XY = 3;   
  10.   
  11.     // Composition pattern   
  12.   
  13.     private Particule target;   
  14.   
  15.     // Constructor   
  16.   
  17.     public TweenableParticule(Particule particule) {   
  18.             this.target = particule;   
  19.     }   
  20.   
  21.     // Tweenable implementation   
  22.   
  23.     @Override  
  24.     public int getTweenValues(int tweenType, float[] returnValues) {   
  25.             switch (tweenType) {   
  26.                     case X: returnValues[0] = target.getX(); return 1;   
  27.                     case Y: returnValues[0] = target.getY(); return 1;   
  28.                     case XY:   
  29.                             returnValues[0] = target.getX();   
  30.                             returnValues[1] = target.getY();   
  31.                             return 2;   
  32.                     default: assert false; return 0;   
  33.             }   
  34.     }   
  35.        
  36.     @Override  
  37.     public void onTweenUpdated(int tweenType, float[] newValues) {   
  38.             switch (tweenType) {   
  39.                     case X: target.setX(newValues[0]); break;   
  40.                     case Y: target.setY(newValues[1]); break;   
  41.                     case XY:   
  42.                             target.setX(newValues[0]);   
  43.                             target.setY(newValues[1]);   
  44.                             break;   
  45.                     default: assert false; break;   
  46.             }   
  47.     }   
  48. }  

最后,在Activity中运动:
Java代码  
  1. import android.app.Activity;   
  2. import android.content.Context;   
  3. import android.graphics.Canvas;   
  4. import android.graphics.Color;   
  5. import android.graphics.Paint;   
  6. import android.os.Bundle;   
  7. import android.view.View;   
  8. import aurelienribon.tweenengine.Tween;   
  9. import aurelienribon.tweenengine.TweenGroup;   
  10. import aurelienribon.tweenengine.TweenManager;   
  11. import aurelienribon.tweenengine.Tweenable;   
  12. import aurelienribon.tweenengine.equations.*;   
  13.   
  14. import com.ql.test.Particule;   
  15. import com.ql.test.TweenableParticule;   
  16.   
  17. /**  
  18.  * http://code.google.com/p/java-universal-tween-engine/  
  19.  * @author admin  
  20.  *  
  21.  */  
  22. public class Screen4 extends Activity {   
  23.     Particule particule;   
  24.     TweenManager manager;   
  25.      @Override  
  26.     public void onCreate(Bundle savedInstanceState) {   
  27.         super.onCreate(savedInstanceState);   
  28. //        setContentView(R.layout.screen_4);   
  29. //      Button btn_11=(Button)findViewById(R.id.btn_11);   
  30.         setContentView(new ScreenView(this));   
  31.         // Let's say we are working with an Android target. We need to pool our objects.   
  32.   
  33.         Tween.setPoolEnabled(true);   
  34.   
  35.         // We also need a manager to handle every tween.   
  36.   
  37.         manager = new TweenManager();   
  38.   
  39.         // We can now create as many interpolations as we need !   
  40.         particule=new Particule();   
  41.         particule.setX(100);   
  42.         particule.setY(100);   
  43.            
  44.         Tweenable tweenParticle=new TweenableParticule(particule);   
  45.            
  46.         Tween tween = Tween.to(tweenParticle, TweenableParticule.XY, 10000, Cubic.OUT).target(400500);   
  47.         manager.add(tween.start());   
  48.   
  49.         tween = Tween.to(tweenParticle, TweenableParticule.XY, 10000, Bounce.OUT).target(100500).delay(10000);   
  50.         manager.add(tween.start());   
  51.            
  52. //      TweenGroup tweenGroup=new TweenGroup().pack(   
  53. //              Tween.set(tweenParticle, TweenableParticule.XY),   
  54. //              Tween.to(tweenParticle, TweenableParticule.XY, 10000, Sine.OUT),   
  55. //              Tween.from(tweenParticle, TweenableParticule.XY, 10000, Sine.OUT),   
  56. //              Tween.to(tweenParticle, TweenableParticule.XY, 10000, Bounce.OUT)   
  57. //              );   
  58. //      manager.add(tweenGroup.sequence().repeat(2,5000).start());   
  59.            
  60. //      TweenGroup tweenGroup= new TweenGroup().pack(   
  61. //              Tween.to(tweenParticle, TweenableParticule.XY, 500, Quad.INOUT).target(200),   
  62. //              Tween.to(tweenParticle, TweenableParticule.XY, 500, Quad.INOUT).target(100),   
  63. //              Tween.to(tweenParticle, TweenableParticule.XY, 500, Quad.INOUT).target(200).delay(1000)   
  64. //          ).sequence().start();   
  65.     }   
  66.   
  67.     @Override  
  68.     protected void onResume() {   
  69.         super.onResume();   
  70.            
  71.     }   
  72.   
  73.     @Override  
  74.     protected void onPause() {   
  75.         super.onPause();   
  76.         manager.clear();   
  77.     }   
  78.   
  79.     class ScreenView extends View{   
  80.   
  81.         Paint paint;   
  82.         public ScreenView(Context context) {   
  83.             super(context);   
  84.             // TODO Auto-generated constructor stub   
  85.             paint=new Paint();   
  86.             paint.setAntiAlias(true);   
  87.             paint.setColor(Color.RED);   
  88.             paint.setStyle(Paint.Style.FILL_AND_STROKE);   
  89.             invalidate();   
  90.         }   
  91.   
  92.         @Override  
  93.         protected void onDraw(Canvas canvas) {   
  94.             // TODO Auto-generated method stub   
  95.             //super.onDraw(canvas);   
  96.             canvas.drawCircle(particule.getX(), particule.getY(), 20, paint);   
  97.             manager.update();   
  98.             invalidate();   
  99.         }   
  100.            
  101.            
  102.     }   
  103. }  
  • aurelienribon.rar (16 KB)
  • 描述: 动画库
  • 下载次数: 16
  • TweenEngine-lib-4.3.zip (29.7 KB)
  • 描述: jar和源码
  • 下载次数: 12