Показать сообщение отдельно
Старый 08.11.2013, 13:22
allex вне форума Посмотреть профиль Отправить личное сообщение для allex Найти все сообщения от allex
  № 5  
Ответить с цитированием
allex

Регистрация: Mar 2012
Сообщений: 46
сделал так -
Код AS3:
package {
	import flash.display.Sprite;
	import flash.events.Event;
	import Box2D.Dynamics.*;
	import Box2D.Collision.*;
	import Box2D.Collision.Shapes.*;
	import Box2D.Common.Math.*;
	public class Main extends Sprite {
		private var world:b2World;
		private var worldScale:Number=30;
		private var theSphere:b2Body;
 
 
		public function Main() {
			world=new b2World(new b2Vec2(0,10),true);
			debugDraw();
			floor();
 
 
			sphere(170, 200, 40);
 
 
			theSphere.ApplyForce(new b2Vec2(0, -10*theSphere.GetMass()),theSphere.GetPosition());
 
			addEventListener(Event.ENTER_FRAME,updateWorld);
		}
		private function sphere(pX:int,pY:int,r:Number):b2Body {
			var bodyDef:b2BodyDef=new b2BodyDef();
			bodyDef.position.Set(pX/worldScale,pY/worldScale);
			bodyDef.type=b2Body.b2_dynamicBody;
			bodyDef.userData=pY;
			var circleShape:b2CircleShape;
			circleShape=new b2CircleShape(r/worldScale);
			var fixtureDef:b2FixtureDef=new b2FixtureDef();
			fixtureDef.shape=circleShape;
			fixtureDef.density=1;
			fixtureDef.restitution=0.4;
			fixtureDef.friction=0.5;
			theSphere=world.CreateBody(bodyDef);
			theSphere.CreateFixture(fixtureDef);
			return theSphere;
		}
		private function floor():void {
			var bodyDef:b2BodyDef=new b2BodyDef();
			bodyDef.position.Set(320/worldScale,465/worldScale);
			var polygonShape:b2PolygonShape=new b2PolygonShape();
			polygonShape.SetAsBox(320/worldScale,15/worldScale);
			var fixtureDef:b2FixtureDef=new b2FixtureDef();
			fixtureDef.shape=polygonShape;
			fixtureDef.restitution=0.4;
			fixtureDef.friction=0.5;
			var theFloor:b2Body=world.CreateBody(bodyDef);
			theFloor.CreateFixture(fixtureDef);
		}
		private function debugDraw():void {
			var debugDraw:b2DebugDraw=new b2DebugDraw();
			var debugSprite:Sprite=new Sprite();
			addChild(debugSprite);
			debugDraw.SetSprite(debugSprite);
			debugDraw.SetDrawScale(worldScale);
			debugDraw.SetFlags(b2DebugDraw.e_shapeBit);
			debugDraw.SetFillAlpha(0.5);
			world.SetDebugDraw(debugDraw);
		}
		private function updateWorld(e:Event):void {
 
			world.Step(1/30,10,10);
 
 
 
			world.ClearForces();
			world.DrawDebugData();
		}
 
	}
}
падает!!!! по идее как в гугле,но инфы не достаточно(

Добавлено через 5 часов 7 минут
В общем надо убрать - [AS3world.ClearForces();][/as3]

Но там не всё так просто,надо разбираться дальше)))

Еще интересная статья - http://www.emanueleferonato.com/2009...es-with-box2d/