2011年6月26日 星期日

Flash Actionscript Physics Engine(APE) II

image

image

image

其中會選用這個工具是因為在其中一個Demo中,右邊這個被命名為SwingDoor的小組件,應該能等合,反抗地心引力(Gravity)的感受

Decompile 後SwingDoor的程式碼如下:

  1: //class SwingDoor
  2: package compcar
  3: {
  4:     import org.cove.ape.*;
  5: 
  6:     public class SwingDoor extends org.cove.ape.Group
  7:     {
  8:         public function SwingDoor(arg1:uint)
  9:         {
 10:             var loc1:*=null;
 11:             var loc2:*=null;
 12:             var loc3:*=null;
 13:             var loc4:*=null;
 14:             var loc5:*=null;
 15:             var loc6:*=null;
 16:             var loc7:*=null;
 17:             super();
 18:             collideInternal=true;
 19:             loc1=new org.cove.ape.CircleParticle(543, 55, 7);
 20:             loc1.mass=0.001;
 21:             loc1.setStyle(1, arg1, 1, arg1);
 22:             addParticle(loc1);
 23:             loc2=new org.cove.ape.CircleParticle(620, 55, 7, true);
 24:             loc2.setStyle(1, arg1, 1, arg1);
 25:             addParticle(loc2);
 26:             (loc3=new org.cove.ape.SpringConstraint(loc1, loc2, 1, true, 13)).setStyle(2, arg1, 1, arg1);
 27:             addConstraint(loc3);
 28: 
 29: 
 30:             (loc4=new org.cove.ape.CircleParticle(543, 5, 2, true)).visible=true;
 31:             loc4.collidable=false;
 32:             addParticle(loc4);
 33: 			
 34:             (loc5=new org.cove.ape.SpringConstraint(loc1, loc4, 0.02)).restLength=40;
 35:             loc5.visible=true;
 36:             addConstraint(loc5);
 37: 			
 38:             (loc6=new org.cove.ape.CircleParticle(550, -60, 70, true)).visible=true;
 39:             addParticle(loc6);
 40: 			
 41:             (loc7=new org.cove.ape.RectangleParticle(650, 130, 42, 70, 0, true)).visible=false;
 42:             addParticle(loc7);
 43:             return;
 44:         }
 45:     }
 46: }
 47: 
 48: 
 49: 


line 19-22 :loc1 : 棒子左邊的點(point),為不固定(fixed = false)



line 23~25: loc2:棒子右邊的點(point),為固定(fixed = true)



line 26~27:loc3: 棒子本身,利用loc1,及loc2串起棒子



棒子可因重物壓過即造成往下掉,和放開時,又往上彈,即時利用了以下二個元素



line 30~32:loc4:在loc1的正上方放即一個點為固定(fixed=true),並設不可碰撞(collidable=false)



line 34~36:loc5:把loc1及loc4用一條線串起來



其中loc4及loc5不希望使用者看到把是否可視設為不可見(visible=false)



line 38~39: 因棒子擺回的動作太大時會造成無法回到原定位,加了一個大球把棒子擋住





image    



image



把loc4~loc7設為可見後,即可清楚其運作



接下應該有機會應用這個範例,加上一些自己的想法,運用在實際專案下,Good Luck






Car Demo Source Code



沒有留言:

張貼留言