我正在尝试用用户拖动的对象来设置一个拉锯。在PhysicsJS中创建世界后,鼠标拖动交互被添加到
world.add( Physics.behavior('interactive', { el: renderer.el }) );效果很好。随后,我希望一些添加的对象是可拖动的(框对象)。但是杠杆不应该是可拖动的,但它应该与盒子相互作用。因此,杠杆应该根据更换的盒子旋转。通过将其treatment属性设置为static,fulcurm以非交互式方式放置。
world.add( Physics.body('convex-polygon', {
name: 'fulcrum',
x: 250,
y: 490,
treatment: 'static',
restitution: 0.0,
vertices: [
{x: 0, y: 0},
{x: 30, y: -40},
{x: 60, y: 0},
]
}) );对象之间如何进行交互,但只有一些对象是用户可拖动的?
小提琴可在:http://jsfiddle.net/YM8K8/上找到
发布于 2014-06-20 15:51:15
目前这不被支持..。但它应该是。我在github上添加了一个bug。https://github.com/wellcaffeinated/PhysicsJS/issues/101
同时,如果需要,您可以通过复制和粘贴创建一个新的“交互式”行为,只需更改名称即可。
Physics.behavior('interactive-custom', function( parent ){ ...然后,在抓取函数中,只需做一个小的添加:
body = self._world.findOne({ $at: new Physics.vector( pos.x, pos.y ) });改为:
body = self._world.findOne({ $at: new Physics.vector( pos.x, pos.y ), $in: self.getTargets() });这样做是当它在鼠标坐标下搜索身体时,它还将检查该主体是否在您应用此行为的集合中。
然后,与其在你的小提琴中的身体之前添加行为,不如在最后添加它,然后这样做:
world.add(
Physics.behavior('interactive-custom', { el: renderer.el })
.applyTo(world.find({ name: 'box' }))
);这将使用world.find来查找目前世界上有“方框”名称的身体。然后,它将一系列的身体发送到行为中,并告诉行为只适用于那些身体。
这是修改过的小提琴:
http://jsfiddle.net/wellcaffeinated/YM8K8/1/
https://stackoverflow.com/questions/24311432
复制相似问题