WEB开发网
开发学院图形图像Flash 在flash中用双向链表实现受控动画 阅读

在flash中用双向链表实现受控动画

 2010-07-22 00:00:00 来源:WEB开发网   
核心提示: 链表:01publicclassLinkedList{02privatevar_head:ListNode;03privatevar_tail:ListNode;04publicfunctionLinkedList(){05_head=newListNode(null);06_tail=newL

链表:

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 }

上一页  1 2 

Tags:flash 中用 双向

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接