Cocos2d x 物理实体在浏览器中移动,但不在mac或ios上移动

Cocos2d x 物理实体在浏览器中移动,但不在mac或ios上移动,cocos2d-x,chipmunk,cocos2d-js,Cocos2d X,Chipmunk,Cocos2d Js,我试图通过在scheduler中更改物理体的坐标来移动它,我使用了以下代码。若我在浏览器中运行这段代码,它会工作,但在js绑定后,它在mac或ios上不工作。物理体在这些设备上根本不运动 init: function{ var mass = 1; var width = 1, height = 1; this.playerBody = new cp.Body(mass , cp.momentForBox(mass, width, height)); this.space.addBody

我试图通过在scheduler中更改物理体的坐标来移动它,我使用了以下代码。若我在浏览器中运行这段代码,它会工作,但在js绑定后,它在mac或ios上不工作。物理体在这些设备上根本不运动

init: function{
 var mass = 1;    
var width = 1, height = 1;
this.playerBody = new cp.Body(mass , cp.momentForBox(mass, width, height));
this.space.addBody(this.playerBody);

this.schedule(this.move);
},
move: function(dt){
this.space.step(dt);
this.playerBody.getPos().x += 2 * dt;
this.playerBody.getPos().y += 2 * dt;
}

尝试从这些行中删除
getPos()
,将它们保留在:
this.playerBody.p.x+=2*dt。我想这很可能是你问题的原因


此外,避免自己操纵坐标,让物理引擎处理一切

例如,可以手动指定速度,如下所示:

init: function{
  var mass = 1;    
  var width = 1, height = 1;
  var vx = 1, vy = 1;
  this.playerBody = new cp.Body(mass , cp.momentForBox(mass, width, height));
  this.space.addBody(this.playerBody);
  this.playerBody.vx = vx;
  this.playerBody.vy = vy;

  this.schedule(this.move);
},

move: function(dt){
  this.space.step(dt);
}
init: function{
  var mass = 1;    
  var width = 1, height = 1;
  var fx = 1, fy = 1;
  this.playerBody = new cp.Body(mass , cp.momentForBox(mass, width, height));
  this.space.addBody(this.playerBody);
  this.playerBody.applyImpuse(cp.v(fx, fy), cp.v(0,0));

  this.schedule(this.move);
},

move: function(dt){
  this.space.step(dt);
}
或者,如果您想在某个方向上对对象进行“凹凸”,您可以像这样使用
applyImpulse

init: function{
  var mass = 1;    
  var width = 1, height = 1;
  var vx = 1, vy = 1;
  this.playerBody = new cp.Body(mass , cp.momentForBox(mass, width, height));
  this.space.addBody(this.playerBody);
  this.playerBody.vx = vx;
  this.playerBody.vy = vy;

  this.schedule(this.move);
},

move: function(dt){
  this.space.step(dt);
}
init: function{
  var mass = 1;    
  var width = 1, height = 1;
  var fx = 1, fy = 1;
  this.playerBody = new cp.Body(mass , cp.momentForBox(mass, width, height));
  this.space.addBody(this.playerBody);
  this.playerBody.applyImpuse(cp.v(fx, fy), cp.v(0,0));

  this.schedule(this.move);
},

move: function(dt){
  this.space.step(dt);
}
或者,如果要对对象应用恒定力,请在最后一个示例中将
applyImpulse
更改为
applyForce

注意:
cp.v(0,0)
参数告诉发动机将力施加到物体的中心,因此不应旋转


PS:若(且仅当)你们碰巧在物理模拟中看到一些奇怪的行为,看看。

在添加了几行之后,我的播放器开始在mac中移动

init: function{
var mass = 1;    
var width = 1, height = 1;
this.playerBody = new cp.Body(mass , cp.momentForBox(mass, width, height));
this.space.addBody(this.playerBody);

this.schedule(this.move);
},
move: function(dt){
this.space.step(dt);
var a = this.playerBody.local2World(this.playerBody.p);
a.y += 2 * dt;
a.x += 2 * dt ;
a = this.playerBody.world2Local(a);
this.playerBody.p = a;
}

但是我没有解释这段代码

首先,我尝试了“this.playerBody.x”,但它不起作用,因为Body类中没有这样的属性。而且,我知道你说的所有这些,我只是想知道为什么我不能在mac中更改物理体的坐标,但是我可以在浏览器中更改它们,而不需要任何麻烦。对不起,我有一个打字错误。
this.playerBody.p.x
“this.playerBody.getPos().x”和“this.playerBody.p.x”这两个语句都是相同的,因为**getPos()**返回对象p,所以您可以通过函数获取它或直接访问它。这两个进程都将访问对象p OK。。这确实很奇怪。可能是因为某种访问保护问题。。你能在官方网站的问题追踪者处提交一份错误报告来描述整个过程吗?