相关代码片段如下:
先有一个类的定义
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();
先有一个类的定义
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();
var Shape3 = new b2BoxDef();
这句里就有了吗?请大虾示例下。
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});
JS版和C++版有出入,看了半天源代码