Game Development Reference
In-Depth Information
3.
Finally, in the Main function we add and stylize the text monitor field.
Something very basic and easy, just a big white text, as this is out of
the scope of this chapter.
public function Main() {
world=new b2World(new b2Vec2(0,5),true);
debugDraw();
addChild(textMon);
textMon.textColor=0xffffff;
textMon.width=300;
textMon.height=300;
textFormat.size=25;
textMon.defaultTextFormat=textFormat;
brick(275,435,30,30,"breakable");
brick(365,435,30,30,"breakable");
brick(320,405,120,30,"breakable");
brick(320,375,60,30,"unbreakable");
brick(305,345,90,30,"breakable");
brick(320,300,120,60,"unbreakable");
idol(320,242);
floor();
addEventListener(Event.ENTER_FRAME,updateWorld);
stage.addEventListener(MouseEvent.CLICK,destroyBrick);
}
Back to serious things now, we need to somehow identify the idol.
One approach uses the userData property that we just looked at.
4.
So we are adding it just like we made with the bricks. This time we'll
be using idol rather than breakable or unbreakable .
private function idol(pX:Number,pY:Number):void {
var bodyDef:b2BodyDef=new b2BodyDef();
bodyDef.position.Set(pX/worldScale,pY/worldScale);
bodyDef.type=b2Body.b2_dynamicBody;
bodyDef.userData="idol";
var polygonShape:b2PolygonShape=new b2PolygonShape();
polygonShape.SetAsBox(5/worldScale,20/worldScale);
var fixtureDef:b2FixtureDef=new b2FixtureDef();
fixtureDef.shape=polygonShape;
fixtureDef.density=1;
fixtureDef.restitution=0.4;
fixtureDef.friction=0.5;
var theIdol:b2Body=world.CreateBody(bodyDef);
theIdol.CreateFixture(fixtureDef);
var bW:Number=5/worldScale;
 
Search WWH ::




Custom Search