如何在 Matter.js 中移动相机

Dan*_*ela 0 matter.js

如何将相机移动到 Matter.js 中的特定位置?

我希望摄像机跟随我的主角。

我尝试了这个教程:http://brm.io/matter-js/demo/#views 但说实话,我不明白它。

Dan*_*ela 6

我找到了制作方法:http://codepen.io/vanuatu/pen/VeQMpp

我们需要控制渲染边界,如下所示:

//
hero = bubbleBall

// Follow Hero at X-axis
engine.render.bounds.min.x = centerX + hero.bounds.min.x
engine.render.bounds.max.x = centerX + hero.bounds.min.x + initialEngineBoundsMaxX

// Follow Hero at Y-axis
engine.render.bounds.min.y = centerY + hero.bounds.min.y
engine.render.bounds.max.y = centerY + hero.bounds.min.y + initialEngineBoundsMaxY

// Update Mouse
Mouse.setOffset(mouseConstraint.mouse, engine.render.bounds.min);
Run Code Online (Sandbox Code Playgroud)

我希望这可以帮助某人