【问题标题】:PHYSICSJS: body shrinks when staticPHYSICSJS:静态时身体收缩
【发布时间】:2014-05-08 00:32:30
【问题描述】:

我有一个非常简单的动画——只是一个位于多边形上的矩形。当我使多边形静态时,它会缩小。最终,我只想做一个斜面模型。很简单。我错过了什么?:

define(
    [
    'underscore',
    'jquery',
    'physicsjs'

    ], 
    function(underscore,$,
        Physics
   ) {

Physics(function(world){
      var viewWidth = 700;
      var viewHeight = 500;
      var center = Physics.vector(viewWidth, viewHeight).mult(0.5)
      var renderer = Physics.renderer('canvas', {
        el: 'viewport',
        width: viewWidth,
        height: viewHeight,

    });

  // add the renderer
  world.add( renderer );

var  ang = 38
var square = Physics.body('rectangle',{
  x: 320,
  y: 380,
  width: 50,
  height: 25,
  vx:0.0,

  angle:ang*Math.PI/180.,
  styles: {
    fillStyle: '#d33682'
  }

});
world.add(square);


world.add( Physics.body('convex-polygon', {
    x: 400,
    y: 500,
    vx: 0,
    cof: 1,
    vertices: [
        {x: 0, y: 0},
        {x: 400, y: 0},
        {x: 0, y: -300},

    ],
    treatment: 'static',
  styles: {
    fillStyle: '#FFEF73'
  }
}) );



world.add(Physics.behavior('constant-acceleration'))

var bounds = Physics.aabb(0,0,viewWidth,viewHeight);

world.add(Physics.behavior('edge-collision-detection', {
  aabb: bounds,
  restitution: 0.3
}));
world.add(Physics.behavior('body-impulse-response'))


world.add(Physics.behavior('body-collision-detection', {
}));
world.add(Physics.behavior('sweep-prune'));

Physics.util.ticker.on(function(time,dt){
  world.step(time);
});

Physics.util.ticker.start();

world.on('step',function(){
  world.render();
});

});
});

【问题讨论】:

  • 你能发布整个代码,或者更好的是,一个 jsfiddle 的链接吗?
  • 请原谅我缺乏经验。我在获取 jfiddle 上链接的 0.6.0 版代码时遇到问题。我不想把它扔到我的个人网站上,也不知道如何链接到你的 git 页面。

标签: physicsjs


【解决方案1】:

有多种因素使它看起来像“缩小”。

实际发生的情况是您的视口尺寸小于三角形。当您将其设置为静态时,它不会被限制在边缘内,因此它的一部分位于渲染区域之外。当您将其设置为“动态”时,它将按照“边缘碰撞检测”的指示跳入渲染区域。

所以解决这个问题,尝试缩小三角形,或增加视口的大小。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-06
    相关资源
    最近更新 更多