Fil*_*zzi 5 javascript p2 game-physics phaser-framework
如何在Phaser.P2.body中施加摩擦力?在基于Air-Hockey移相器的游戏中.如何从曲棍球台"关闭气流"?
在这个例子中:http://jsfiddle.net/ywzmkso3/32/
// Initialize Phaser, and creates a 400x490px game
var game = new Phaser.Game(400, 400, Phaser.CANVAS, 'game_div');
var game_state = {};
// Creates a new 'main' state that wil contain the game
game_state.main = function() { };
game_state.main.prototype = {
preload: function() {
// Function called first to load all the assets
},
create: function() {
game.physics.startSystem(Phaser.Physics.P2JS);
game.physics.p2.restitution = 0.7;
//start drawing a circle
var graphics = game.add.graphics(0, 0);
graphics.beginFill(0xFF3300);
graphics.lineStyle(0);
graphics.beginFill(0xFFFF0B);
graphics.drawCircle(100, 100, 40);
graphics.endFill();
//creating an sprite from draw
var spriteCircle = game.add.sprite(100, 300, graphics.generateTexture());
// And destroy the original graphics object
graphics.destroy();
spriteCircle.anchor.set(0.5);
game.physics.p2.enable([ spriteCircle ], false);
spriteCircle.body.setCircle(20);// 20 radius
spriteCircle.body.mass = 1;
spriteCircle.body.debug = true;
//give some initial velocity
spriteCircle.body.velocity.x = 10000
spriteCircle.body.velocity.y = 19999
},
update: function() {
},
};
// Add and start the 'main' state to start the game
game.state.add('main', game_state.main);
game.state.start('main');
Run Code Online (Sandbox Code Playgroud)
如果表是打开的话,这是一个非常好的和现实的例子..但是......如果表是关闭的?puc应该移动得更慢,并且应该有更短的停止.我想模仿那个.想象黄色圆圈是空气球冰球,黑色背景是那些充气桌子之一.如何设置puc和桌子之间的摩擦力?
P2文档似乎有许多与碰撞和与身体边缘和材料接触有关的事情......但是如何模拟与"空气"的摩擦?或"水",如果这个身体在游泳..或与冰球和桌子摩擦?
PS.尝试降级更新()中的P2.body.velocity.x和y会促进奇怪的重新路由行为.
您正在寻找Phaser P2的damping属性,它将物质体引入拖拽.
将它添加到您的身体,冰球很快停止,好像空气已经关闭:
spriteCircle.body.damping = 0.9;
Run Code Online (Sandbox Code Playgroud)
阻尼指定速度的比例丢失每个第二,和有效的值的范围是0到1.
用阻尼更新了JSFiddle:http://jsfiddle.net/Lucgmptn/