在flash中用双向链表实现受控动画
2010-07-22 00:00:00 来源:WEB开发网链表:
01 public class LinkedList{
02 private var _head : ListNode;
03 private var _tail : ListNode;
04 public function LinkedList(){
05 _head = new ListNode(null);
06 _tail = new ListNode(null);
07
08 _head.next = _tail;
09 _tail.previous = _head;
10 }
11 public function add(item:IActionFrame):void{
12 if (item == null) return;
13 var newNode : ListNode = new ListNode(item);
14
15 var currentNode : ListNode = _head.next;
16 while (currentNode != null){
17 if (currentNode == _tail){
18 _tail.previous.next = newNode;
19 newNode.next = _tail;
20 tail.previous = newNode;
21 break;
22 }
23
24 if (currentNode.item.nextActionFrame > newNode.nextActionFrame){
25 currentNode.previous.next = newNode;
26 currentNode.previous = newNode;
27 newNode.previous = currentNode.previous;
28 newNode.next = newNode;
29 break;
30 }
31 currentNode = currentNode.next;
32 }
33 }
34
35 //移除列表中的item
36 public function remove(item:IActionFrame):void{
37 if (item == null)return;
38 if (_head.next == _tail) return;
39 var currentNode : ListNode = _head.next;
40 while (currentNode != tail){
41 if (currentNode.item == item){
42 currentNode.previous.next = currentNode.next;
43 currentNode.next.previous = currentNode.previous;
44 break;
45 }
46 currentNode = currentNode.next;
47 }
48 }
49
50 //获取下一个需要处理的对象,同时从列表中移除此对象
51 public function nextActiveFrame(currentFrame:uint):IActionFrame{
52 if (_tail.next == _tail) return null;
53 if (_tail.next.item.nextActionFrame > currentFrame) return null;
54 var result : ListNode = _tail.next;
55
56 _tail.next = _tail.next.next;
57 _tail.next.previous = _tail;
58
59 return result.item;
60 }
61 }
最后修改AnimationDispatcher类,使之能管理所有的动画:
01 public class AnimationDispatcher{
02 private var _frameCounter : uint;
03 private var _list : LinkedList = new LinkedList();
04
05 public function listenEnterFrame(e:Event):void{
06 _frameCounter++;
07 while ((var item : IActionFrame = _list.nextActiveFrame) != null){
08 //执行动作及处理下一帧间隔
09 item.doAction();
10 if (item.needToPushBack()){
11 _list.add(item);
12 }
13 }
14 }
15 }
- ››FLASH不等于运算符!=的使用实例
- ››FLASH不全等运算符!==
- ››FLASH字符串分隔符运算符
- ››FLASH% 模运算符
- ››Flash+、++、+= 加法运算符
- ››Flash, 逗号运算符
- ››flash中的-、--、-=减法运算符
- ››Flash的-Infinity 常数、.点运算符、/ 除法运算符...
- ››Flash两种注释方法/*..*/ 和// 注释行分隔符运算符...
- ››Flash的/=除法赋值运算符、=赋值运算符、== 等于运...
- ››Flash之?: 条件运算符、^ 按位 XOR 运算符、^= 按...
- ››Flash的_framesloaded代码示例
更多精彩
赞助商链接