相关代码片段如下:
先有一个类的定义
var b2Shape = Class.create();
b2Shape.prototype = 
{
GetType: function(){
return this.m_type;
},
GetBody: function(){
return this.m_body;
}, GetPosition: function(){
return this.m_position;
},
.........
        .........
};接着有如下语句:var Shape3 = new b2BoxDef();    //Shape3:矩形 Shape3.extents.Set(600, 5);         //定义矩形高、宽
Shape3.density = 0;                 //墙体密度为0
Shape3.restitution = .3;            //弹性
Shape3.friction = 1;                //摩擦力
Shape3.GetType();
报错
Shape3.GetType is not a function
[在此错误处中断] Shape3.GetType(); 

解决方案 »

  1.   

    从你提供的代码可以猜到,b2BoxDef类继承了b2Shape类,不过从你的代码的效果可以看错,没有继承,楼主要把继承那部分的代码给出来
      

  2.   

    是的啊,就是在弄box2d JS版,继承的那段代码?不是在
    var Shape3 = new b2BoxDef(); 
    这句里就有了吗?请大虾示例下。 
      

  3.   

    找到了这么一段:
    var b2BoxDef = Class.create();
    Object.extend(b2BoxDef.prototype, b2ShapeDef.prototype);
    Object.extend(b2BoxDef.prototype, 
    {
    initialize: function()
    {
    // The constructor for b2ShapeDef
    this.type = b2Shape.e_unknownShape;
    this.userData = null;
    this.localPosition = new b2Vec2(0.0, 0.0);
    this.localRotation = 0.0;
    this.friction = 0.2;
    this.restitution = 0.0;
    this.density = 0.0;
    this.categoryBits = 0x0001;
    this.maskBits = 0xFFFF;
    this.groupIndex = 0;
    // this.type = b2Shape.e_boxShape;
    this.extents = new b2Vec2(1.0, 1.0);
    }, extents: null});
      

  4.   

    查到  b2BoxDef  派生于  b2ShapeDef   但没看到  b2ShapeDef 和  b2Shape之间有什么关系,所以也就没法调用  b2Shape  的  GetPosition()函数了。  大家有什么办法在BOX2D中获取一个物体的位置吗?
      

  5.   

    你就继承一下,位置?如果你可以获取css的属性
      

  6.   

    因为在BOX2D中没看到继承关系,也不敢随便乱改,怕搞坏掉。应该有现成什么函数来获取移动的物体的坐标,否则它也没法移动了。
      

  7.   

    可用Body3.GetCenterPosition().x或者Shape3.localPosition.x
    JS版和C++版有出入,看了半天源代码