0

在 box2D 中,我使用这个 js 函数来创建一个绿色框:

createBox(world, 8.50, 3.80, 1 , 1, {type : b2Body.b2_dynamicBody, 'user_data' : {'fill_color' : 'rgba(204,237,165,1)' , 'border_color' : '#7FE57F' }});

功能在这里:

function createBox(world, x, y, width, height, options) 
{

     //default setting
    options = $.extend(true, {
        'density' : 2.5 ,
        'friction' : 2.0 ,
        'restitution' : 2.5 ,

        'type' : b2Body.b2_dynamicBody
    }, options);

    var body_def = new b2BodyDef();
    var fix_def = new b2FixtureDef();

    fix_def.density = options.density;
    fix_def.friction = options.friction;
    fix_def.restitution = options.restitution;

    fix_def.shape = new b2PolygonShape();

    fix_def.shape.SetAsBox( width/2 , height/2 );

    body_def.position.Set(x , y);

    body_def.type = options.type;

    body_def.userData =options.user_data;

    var b = world.CreateBody( body_def );
    var f = b.CreateFixture(fix_def);

    return b;
}

当我尝试制作static对象时,它会变成绿色,但对于dynammic对象它不会。我究竟做错了什么?

4

0 回答 0