衝突判定テスト1
♥0 |
Line 28 |
Modified 2011-01-05 22:58:58 |
MIT License
archived:2017-03-20 01:01:35
ActionScript3 source code
/**
* Copyright Ryogo_Quberey ( http://wonderfl.net/user/Ryogo_Quberey )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/nDG2
*/
package {
import flash.display.Sprite;
import flash.display.MovieClip;
import com.actionsnippet.qbox.*;
import Box2D.Common.Math.*;
import flash.events.Event;
import flash.utils.*;
public class FlashTest extends MovieClip {
public function FlashTest() {
[SWF(width = 1400, height = 600, backgroundColor = 0x000000, frameRate=60)]
var sim:QuickBox2D = new QuickBox2D(this, {debug:false, frim:true});
sim.setDefault({lineAlpha:0});
sim.createStageWalls({fillColor:0xFFFFFF});
var boxA:QuickObject = sim.addBox({x:3, y:3, width:2, height:2, fillColor:0xFF0000});
var boxB:QuickObject = sim.addBox({x:3, y:6, width:2, height:2, fillColor:0xFF0000});
sim.start();
sim.mouseDrag();
// when boxA touches boxB a circle QuickObject is created
var contacts:QuickContacts = sim.addContactListener();
// listen for contact points being added
contacts.addEventListener(QuickContacts.ADD, onAdd);
function onAdd(evt:Event):void{
// see if this contact event is associated with boxA and boxB
if(contacts.isCurrentContact(boxA, boxB)){
// get the location of the collision in world space
var loc:b2Vec2 = contacts.currentPoint.position;
// you cannot create new QuickObjects inside this listener function
// so we just give a 5 ms delay
setTimeout(sim.addCircle, 5, {x:loc.x, y:loc.y});
}
}
// write as3 code here..
}
}
}