你知道我是否可以与 as3isolib 集成一些物理引擎,如颈背或 box2d 吗?

发布于 2025-01-05 08:12:19 字数 70 浏览 0 评论 0原文

我只是在寻找任何解释或教导如何将 as3isolib 与某些物理引擎(如颈背或 box2d)集成(如果可能)的资源。有可能吗?

i just searching for any resource that explain or teach how integrate if it possible as3isolib with some physics engine like, nape or box2d. It is possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

赤濁 2025-01-12 08:12:19

当然你可以做到。
例如Box2D Body有成员userData,其类型为*,因此您可以在那里分配任何数据。
由于 Box2D 和 nape 是 2D 物理引擎,您可以在 x 和 y 轴上进行 2d 物理修改。
这是一个例子:

package 
{
    import as3isolib.display.primitive.IsoBox;
    import as3isolib.display.scene.IsoScene;

    import Box2D.Dynamics.Contacts.*;
    import Box2D.Dynamics.*;
    import Box2D.Collision.*;
    import Box2D.Collision.Shapes.*;
    import Box2D.Common.Math.*;
    import Box2D.Dynamics.Joints.*;


    import flash.events.Event;

    import flash.display.Sprite;

    public class Main extends Sprite
    {
        private var scene:IsoScene;
        private var world:b2World;
        private var gravity:b2Vec2;
        private var body:b2Body;
        private const worldScale:int = 30;
        private const doSleep:Boolean = true;
        private static const m_iterations:int = 10;
        private static const m_timeStep:Number = 1.0/30.0;


        public function Main ()
        {
            scene = new IsoScene();
            scene.hostContainer = this;

            var bodyDef:b2BodyDef;
            var fixtureDef:b2FixtureDef = new b2FixtureDef();

            gravity = new b2Vec2(0.0, 4.0);
            world = new b2World(gravity, doSleep);

            bodyDef = new b2BodyDef();
            bodyDef.type=b2Body.b2_dynamicBody;
            bodyDef.allowSleep = false;
            bodyDef.linearDamping = 1;
            bodyDef.angularDamping = 1;
            bodyDef.position.x = 200/worldScale; //position
            bodyDef.position.y = 100/worldScale; //position
            bodyDef.userData = new IsoBox();
            bodyDef.userData.setSize(25, 25, 25);
            bodyDef.fixedRotation = true;
            fixtureDef.restitution = 0.5;
            fixtureDef.shape = new b2CircleShape(0.3);
            fixtureDef.density = 1;
            fixtureDef.friction = 5;
            fixtureDef.restitution = 0.5;

            scene.addChild(bodyDef.userData);

            body = world.CreateBody(bodyDef);
            body.CreateFixture(fixtureDef);

            addEventListener(Event.ENTER_FRAME, Update);
        }

        private function Update(e:Event):void
        {
            world.Step(m_timeStep, m_iterations, m_iterations);
            world.ClearForces();
            body.GetUserData().moveTo(body.GetPosition().x * worldScale, body.GetPosition().y * worldScale, 0);

            scene.render();
        }
    }
}

Sure you can do that.
For example Box2D Body has member userData, which type is *, so you can assign any data there.
As far as Box2D and nape are 2D physics engines, you can make 2d phys modifications on x and y axis.
Here is an example:

package 
{
    import as3isolib.display.primitive.IsoBox;
    import as3isolib.display.scene.IsoScene;

    import Box2D.Dynamics.Contacts.*;
    import Box2D.Dynamics.*;
    import Box2D.Collision.*;
    import Box2D.Collision.Shapes.*;
    import Box2D.Common.Math.*;
    import Box2D.Dynamics.Joints.*;


    import flash.events.Event;

    import flash.display.Sprite;

    public class Main extends Sprite
    {
        private var scene:IsoScene;
        private var world:b2World;
        private var gravity:b2Vec2;
        private var body:b2Body;
        private const worldScale:int = 30;
        private const doSleep:Boolean = true;
        private static const m_iterations:int = 10;
        private static const m_timeStep:Number = 1.0/30.0;


        public function Main ()
        {
            scene = new IsoScene();
            scene.hostContainer = this;

            var bodyDef:b2BodyDef;
            var fixtureDef:b2FixtureDef = new b2FixtureDef();

            gravity = new b2Vec2(0.0, 4.0);
            world = new b2World(gravity, doSleep);

            bodyDef = new b2BodyDef();
            bodyDef.type=b2Body.b2_dynamicBody;
            bodyDef.allowSleep = false;
            bodyDef.linearDamping = 1;
            bodyDef.angularDamping = 1;
            bodyDef.position.x = 200/worldScale; //position
            bodyDef.position.y = 100/worldScale; //position
            bodyDef.userData = new IsoBox();
            bodyDef.userData.setSize(25, 25, 25);
            bodyDef.fixedRotation = true;
            fixtureDef.restitution = 0.5;
            fixtureDef.shape = new b2CircleShape(0.3);
            fixtureDef.density = 1;
            fixtureDef.friction = 5;
            fixtureDef.restitution = 0.5;

            scene.addChild(bodyDef.userData);

            body = world.CreateBody(bodyDef);
            body.CreateFixture(fixtureDef);

            addEventListener(Event.ENTER_FRAME, Update);
        }

        private function Update(e:Event):void
        {
            world.Step(m_timeStep, m_iterations, m_iterations);
            world.ClearForces();
            body.GetUserData().moveTo(body.GetPosition().x * worldScale, body.GetPosition().y * worldScale, 0);

            scene.render();
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文