flash on 2010-3-15
衝突したときのイベントの練習
/**
* Copyright hacker_kirifla ( http://wonderfl.net/user/hacker_kirifla )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/uMNq
*/
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:3,y:3,width:2,height:2,fillColor:0xff0000});
boxB=sim.addBox({x:3,y:6,width:2,height:2,fillColor:0x00ff00});
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=10;
boxA.userData.height=10;
boxB.userData.width=10;
boxB.userData.height=10;
}
}
}
}