我正在使用PhysicsJS创建一个杂耍游戏。我只有一个球(圆形)和一只鞋(使用凸多边形形状的方形)。鞋子设置为固定并在 mousemove 上沿 x 轴移动。
正方形:
square = Physics.body('convex-polygon', {
x: 250,
y: 400,
vertices: [
{ x: -68, y: 29 },
{ x: 68, y: 29 },
{ x: 69, y: -29 },
{ x: -68, y: -29 }
],
angle: -0.2,
view: shoeImage,
fixed: true,
restitution: 1
});
world.add(square);
鼠标移动事件:
jQuery('canvas').on('mousemove', function (e) {
var offset = $(this).offset();
var relativeX = (e.pageX - offset.left);
square.state.pos.set(relativeX, 400);
});
我还在鞋子上添加了一个点击事件以产生“踢球效果”。到目前为止,我已经通过更改square.state.angular.pos
并使用函数将其设置回之前的角度位置来完成此操作setTimeout
。
jQuery('canvas').on('click', function (e) {
if (square.state.angular.pos == -0.2) {
square.state.angular.pos = 0.3;
}
else {
square.state.angular.pos = -0.2;
}
setTimeout(function() { resetShoe(square); }, 500);
});
function resetShoe(square) {
if (square.state.angular.pos == -0.2) {
square.state.angular.pos = 0.3;
}
else {
square.state.angular.pos = -0.2;
}
}
你可以看到它在这里工作。它工作得很好,但我希望这是动画而不是定格动画。我只是想不出办法。