0

私は非常に単純なアニメーションを持っています - 多角形の上にある長方形だけです。ポリゴンを静的にすると縮小します。最終的には、傾斜面モデルを作成したいだけです。とてもシンプルです。何が欠けていますか?:

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();
});

});
});
4

1 に答える 1

2

形が「縮んでいる」ように見えるものの組み合わせがあります。

実際に起こっているのは、ビューポートのサイズが三角形よりも小さいということです。静的に設定すると、エッジ内に拘束されないため、一部がレンダリング領域の外にあります。「動的」に設定すると、「エッジ衝突検出」の指示に従ってレンダリング領域にジャンプします。

これを解決するには、三角形を縮小するか、ビューポートのサイズを大きくしてください。

于 2014-05-07T16:32:30.717 に答える