Example, removed gravity, removed friction, made maximum elasticity. The balls still stop. What else can you do to make the balls move endlessly? Or is this a phaser js bug?
var config = {
type: Phaser.AUTO,
width: 800,
height: 600,
physics: {
default: 'matter',
matter: {
debug: true,
gravity: { y: 0 } // Отключаем гравитацию для этой сцены
}
},
scene: {
preload: preload,
create: create
}
};
function preload() {
// Здесь можно загрузить изображения, если нужно использовать вместо примитивных фигур
}
function create() {
//this.matter.world.setBounds(0, 0, 800, 600);
let width = this.game.config.width;
let height = this.game.config.height;
// Параметры для стенок
let wallOptions = {
isStatic: true,
restitution: 1,
friction: 0,
frictionAir: 0,
};
// Верхняя стенка
this.matter.add.rectangle(width / 2, 0, width, 10, wallOptions);
// Нижняя стенка
this.matter.add.rectangle(width / 2, height, width, 10, wallOptions);
// Левая стенка
this.matter.add.rectangle(0, height / 2, 10, height, wallOptions);
// Правая стенка
this.matter.add.rectangle(width, height / 2, 10, height, wallOptions);
// Создание 10 круглых объектов
for (let i = 0; i < 10; i++) {
// Создаем круглый объект с радиусом 15
let circle = this.matter.add.circle(Phaser.Math.Between(100, 700), Phaser.Math.Between(100, 500), 15, {
restitution: 1, // Полная упругость для отскока без потерь
friction: 0, // Уменьшение трения для минимизации потерь скорости
frictionAir: 0,
render: {
fillStyle: '#ff0000' // Задаем красный цвет заливки
}
});
// Задаем объекту случайный импульс
this.matter.body.applyForce(circle, { x: circle.position.x, y: circle.position.y }, {
x: (Math.random() - 0.5) * 0.05,
y: (Math.random() - 0.5) * 0.05
});
}
// Создание 10 статичных квадратных объектов
for (let i = 0; i < 10; i++) {
// Создаем статичный квадратный объект со стороной 50
this.matter.add.rectangle(Phaser.Math.Between(100, 700), Phaser.Math.Between(100, 500), 50, 50, {
isStatic: true,
restitution: 1, // Полная упругость
friction: 0, // Уменьшение трения
render: {
fillStyle: '#ff0000' // Задаем красный цвет заливки
}
});
}
}
var game = new Phaser.Game(config);
[https://codepen.io/attfcwtz-the-encoder/pen/QWoovQq][1]
I didn’t figure out how to add links to codepen here, the validator just missed it. [1]: https://codepen.io/attfcwtz-the-encoder/pen/QWoovQq