WEB开发网
开发学院图形图像Flash Simplify your Box2D projects with QuickBox2D 阅读

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 Fl

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…

本文示例源代码或素材下载

Tags:Simplify your BoxD

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接