Box2dWeb模拟自由落体重力效果

代码语言:html

所属分类:动画

代码描述:Box2dWeb模拟自由落体重力效果

代码标签: 重力 效果

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<html>
<head>
    <title>Box2dWeb example</title>
</head>
<body onload="init();">
    <canvas id="canvas" width="600" height="400"></canvas>

    <script type="text/javascript" src="http://repo.bfw.wiki/bfwrepo/js/Box2dWeb-2.1.js"></script>
    <script type="text/javascript">
        var world;

        function init() {
            var   b2Vec2 = Box2D.Common.Math.b2Vec2,
            b2BodyDef = Box2D.Dynamics.b2BodyDef,
            b2Body = Box2D.Dynamics.b2Body,
            b2FixtureDef = Box2D.Dynamics.b2FixtureDef,
            b2Fixture = Box2D.Dynamics.b2Fixture,
            b2World = Box2D.Dynamics.b2World,
            b2MassData = Box2D.Collision.Shapes.b2MassData,
            b2PolygonShape = Box2D.Collision.Shapes.b2PolygonShape,
            b2CircleShape = Box2D.Collision.Shapes.b2CircleShape,
            b2DebugDraw = Box2D.Dynamics.b2DebugDraw;

            world = new b2World(
                new b2Vec2(0, 10)    //gravity, true                 //allow sleep
            );

            var fixDef = new b2FixtureDef;
            fixDef.density = 1.0;
            fixDef.friction = 0.5;
            fixDef.restitution = 0.2;

            var bodyDef = new b2BodyDef;

            //create ground
            bodyDef.type = b2Body.b2_staticBody;
            bodyDef.position.x = 9;
            bodyDef.position.y = 13;
            fixDef.shape = new b2PolygonShape;
            fixDef.shape.SetAsBox(10, 0.5);
            world.CreateBody(bodyDef).CreateFixtur.........完整代码请登录后点击上方下载按钮下载查看

网友评论0