Box2D
Box2D
package {
import flash.display.Sprite;
import flash.display.MovieClip;
import com.actionsnippet.qbox.*;
import Box2D.Common.Math.*;
import flash.events.Event;
import flash.media.Video;
public class FlashTest extends MovieClip {
private var con:QuickContacts;
private var boxA:QuickObject;
private var boxB:QuickObject;
private var sim:QuickBox2D;
public function FlashTest() {
// write as3 code here..
sim=new QuickBox2D(this);
sim.createStageWalls();
boxA=sim.addBox({x:1,y:1,width:1,height:1,fillColor:0xff5566});
boxB=sim.addBox({x:1,y:1,width:1,height:1,fillColor:0x00ff00});
boxA.userData.width=20;
boxA.userData.height=20;
boxB.userData.width=20;
boxB.userData.height=20;
sim.start();
sim.mouseDrag();
//接触判定のためのQuickContactを作成
con=sim.addContactListener();
con.addEventListener(QuickContacts.ADD,onAdd);
con.addEventListener(QuickContacts.REMOVE,onRemove);
}
private function onRemove(e:Event):void{
if(con.isCurrentContact(boxA,boxB)){
boxA.userData.width=20;
boxA.userData.height=20;
boxB.userData.width=20;
boxB.userData.height=20;
}
}
private function onAdd(e:Event):void{
if(con.isCurrentContact(boxA,boxB)){
boxA.userData.width=20;
boxA.userData.height=20;
boxB.userData.width=20;
boxB.userData.height=20;
}
}
}
}