Simplify your Box2D projects with QuickBox2D
2009-10-18 00:00:00 来源:WEB开发网In this quick example I am going to add a sphere to the stage and make it draggable.
Before looking at this script, take a look at Dragging objects with Box2D Flash to see how many lines of code I needed to make those crates draggable.
This is what you need with QuickBox2D:
package {
import flash.display.MovieClip;
// importing required library
import com.actionsnippet.qbox.*;
// it must be a MovieClip!! With a Sprite it won't work!
public class quickbox extends MovieClip {
public function quickbox() {
// setting up the QuickBox2D world
var qb:QuickBox2D=new QuickBox2D(this);
// default fill color
qb.setDefault({lineAlpha:0, fillColor:0xff0000});
// automatic stage walls creation!!!!!!!
qb.createStageWalls();
// adding a ball... that easy...
var ball:QuickObject=qb.addCircle({x:3,y:3,restitution:0.9,lineAlpha:1,fillColor:0x00ff00,allowSleep:false,fixedRotation:true});
// automatic mouse dragging!!!
qb.mouseDrag();
// starting the simulation
qb.start();
}
}
}
and this is what you get…
本文示例源代码或素材下载
更多精彩
赞助商链接