English 中文(简体)
MatterJS 预示最后立场
原标题:MatterJS precompute final position

我正试图创造一个简单的2D游戏,在这个游戏中,球正在向地面倾斜,受到一些障碍的影响,这些障碍将改变球的最终位置。

我正在使用MattriJS作为2D物理发动机,但实际上无法预测,我的球团总处于不同的最后位置。

是否有办法预断球会走的道路(经常),将球带入一个变数,并在我需要时把它装上同一条道路? 还是能够准确预测最后立场?

最佳回答

I found a way to precompute instantly the path of the ball by calling manually Matter.Engine.update(engine) and storing the position of my ball for each frame.

然后重新定位我的球体位,即:ball.isStatic = 真实;,并在每一行程中人工移动:

Matter.Events.on(engine, "afterUpdate", () => {
    if (positions.length > 0) {
        Matter.Body.setPosition(ball, positions.shift());
    }
});
问题回答

Matter.js is deterministic. The only varying parameter is the deltas, the intervals between the ticks. The results will always be the same for a certain set of deltas.

然而,其精彩的导师,Matter.Render,将照样的标度与显示的标度同步,window.requestAnimationFrame (,因缺而异,因此每当你操作该代码时,三角洲会发生随机变化。

您可以人工使用<代码>。 Matter.Engine.update(engine, delta)。 在your control下打字,了解你的三角关系,结果将一致。

一旦你在浏览器中处理事项,并且需要确定性,你就必须保留<代码>event.source.timing.lastDelta<>code>。

You can achieve it by:

  1. 采用相同的<代码>Engine的航道,供您在全球范围内保存。

  2. Configuring _seed and polyfiling trig functions:

    import trigf from  trigfills ;
    import * as MatterJS from  matter-js ;
    
    trigf.setmaths();
    MatterJS.Common._seed = 13579; // random value but always the same
    
    export default MatterJS;
    
  3. Set Options isFixed: real while establishing Runner

    Runner.create({
      isFixed: true,
    })
    




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签