我如何将对象指向Box2DJS + Cocos2DJS中的某个点

How can I point an object to a certain point in Box2DJS + Cocos2DJS

本文关键字:Cocos2DJS Box2DJS 对象      更新时间:2023-09-26

我正在尝试模拟射箭射击游戏,我想动画弓指向我的鼠标所在的位置。我该怎么做呢?我已经尝试绑定关节并将其用于鼠标跟随:

this.bow.SetTransform(new b2Vec2(x/30, y/30), this.bow.GetAngle());

但是总是出现错误:

Uncaught TypeError: Object [Object Object] has no method 'GetAngle'

我已经搜索了这个错误,但在谷歌中没有找到。是否有一种方法来解决这个问题或另一种方法来实现弓鼠标跟随?

SetTransform方法的源代码如下:

 b2Body.prototype.SetTransform = function (xf) {
      this.SetPositionAndAngle(xf.position, xf.GetAngle());
 }

尝试呼叫SetPositionAndAngle而不是SetTransform