iTween基础之Move(移动)

1,五种移动方法;2, 函数的基础属性及用法

原文地址:http://blog.csdn.net/dingkun520wy/article/details/50476864

iTween官网:http://itween.pixelplacement.com/index.php

1,五种移动方法

MoveTo:从原始位置移动到目标位置。

MoveFrom:从目标位置移动到原始位置。

MoveAdd:随时间移动游戏对象的位置,根据提供的量。

MoveBy:增加提供的坐标到游戏对象的位置。(与MoveAdd一样)

MoveUpdate:类似于MoveTo,在Update()或FixedUpdate()方法或循环环境中调用。提供每帧改变属性值的环境。不依赖于EasrType.

动画的方法一般有两种重载,

a,最小定制选项,只需要提供最少必需参数

//target:要移动的物体;position:要移动的位置;time:动画的运行的时间

public static void MoveUpdate(GameObject target, Vector3 position, float time);

b,完全定制选项,可定制所有的参数

//target:要移动的物体;args:定制的数组

public static void MoveUpdate(GameObject target, Hashtable args);

 

定制移动路径iTweenPath 详细讲解: http://blog.csdn.net/dingkun520wy/article/details/51075774

 

2, 函数的基础属性及用法

基础属性比较简单直接上代码

 

[csharp] view plain copy
 
 在CODE上查看代码片派生到我的代码片
  1. void Start () {  
  2.           
  3.         //键值对儿的形式保存iTween所用到的参数  
  4.         Hashtable args = new Hashtable();  
  5.    
  6.         //这里是设置类型,iTween的类型又很多种,在源码中的枚举EaseType中  
  7.         //例如移动的特效,先震动在移动、先后退在移动、先加速在变速、等等  
  8.         args.Add("easeType", iTween.EaseType.easeInOutExpo);  
  9.    
  10.         //移动的速度,  
  11.         //args.Add("speed",10f);  
  12.         //移动的整体时间。如果与speed共存那么优先speed  
  13.         args.Add("time",10f);  
  14.         //这个是处理颜色的。可以看源码的那个枚举。  
  15.         args.Add("NamedValueColor","_SpecColor");  
  16.         //延迟执行时间  
  17.         args.Add("delay", 0.1f);  
  18.           
  19.         //是否让游戏对象始终面朝路径行进的方向,拐弯的地方会自动旋转。  
  20.         args.Add("orienttopath", true);  
  21.         //移动的过程中面朝一个点,当“orienttopath”为true时该参数失效  
  22.         args.Add("looktarget",Vector3.zero);  
  23.         //游戏对象看向“looktarget”的秒数。  
  24.         args.Add("looktime",1.1);  
  25.   
  26.   
  27.         //游戏对象移动的路径可以为Vector3[]或Transform[] 类型。可通过iTweenPath编辑获取路径  
  28.         Vector3[] testPath = { new Vector3(0, 0, 0), new Vector3(0, 1, 0), new Vector3(0, 1, 1), new Vector3(1, 1, 1), new Vector3(1, 5, 1) };  
  29.         args.Add("path", testPath);  
  30.         //是否移动到路径的起始位置(false:游戏对象立即处于路径的起始点,true:游戏对象将从原是位置移动到路径的起始点)  
  31.         args.Add("movetopath", false);  
  32.   
  33.         //当包含“path”参数且“orienttopath”为true时,该值用于计算“looktarget”的值,表示游戏物体看着前方点的位置,(百分比,默认0.05)  
  34.         args.Add("lookahead",0.01);  
  35.   
  36.         //限制仅在指定的轴上旋转  
  37.         args.Add("axis", "x");  
  38.         //是否使用局部坐标(默认为false)  
  39.         args.Add("islocal", false);  
  40.   
  41.    
  42.         //三个循环类型 none loop pingPong (一般 循环 来回)    
  43.         //args.Add("loopType", "none");  
  44.         //args.Add("loopType", "loop");   
  45.         args.Add("loopType", iTween.LoopType.pingPong);  
  46.    
  47.         //处理移动过程中的事件。  
  48.         //开始发生移动时调用AnimationStart方法,5.0表示它的参数  
  49.         args.Add("onstart", "AnimationStart");  
  50.         args.Add("onstartparams", 5.0f);  
  51.         //设置接受方法的对象,默认是自身接受,这里也可以改成别的对象接受,  
  52.         //那么就得在接收对象的脚本中实现AnimationStart方法。  
  53.         args.Add("onstarttarget", gameObject);  
  54.    
  55.   
  56.         //移动结束时调用,参数和上面类似  
  57.         args.Add("oncomplete", "AnimationEnd");  
  58.         args.Add("oncompleteparams", "end");  
  59.         args.Add("oncompletetarget", gameObject);  
  60.    
  61.         //移动中调用,参数和上面类似  
  62.         args.Add("onupdate", "AnimationUpdate");  
  63.         args.Add("onupdatetarget", gameObject);  
  64.         args.Add("onupdateparams", true);  
  65.    
  66.         // x y z 标示移动的位置。  
  67.         args.Add("x",-5);  
  68.         args.Add("y",1);  
  69.         args.Add("z",1);  
  70.         //当然也可以写Vector3  
  71.         //args.Add("position",Vectoe3.zero);  
  72.         //最终让改对象开始移动  
  73.         iTween.MoveTo(btnBegin, args);    
  74.     }  
  75.     //对象移动中调用  
  76.     void AnimationUpdate(bool f)  
  77.     {  
  78.         Debug.Log("update :" + f);  
  79.     }  
  80.     //对象开始移动时调用  
  81.     void AnimationStart(float f)  
  82.     {  
  83.         Debug.Log("start :" + f);  
  84.     }  
  85.     //对象移动时调用  
  86.     void AnimationEnd(string f)  
  87.     {  
  88.         Debug.Log("end : " + f);  
  89.     }  



 

posted @ 2016-01-20 19:25  乐逍遥Jun  阅读(507)  评论(0编辑  收藏  举报