简体   繁体   English

Phaser - Arcade碰撞物理学

[英]Phaser - Arcade collision physics

I'm working on a simple tile game using the Phaser framework, but unfortunately I've stumbled upon a "bug" when using the Arcade collision method. 我正在使用Phaser框架进行简单的平铺游戏,但遗憾的是,在使用Arcade碰撞方法时,我偶然发现了一个“错误”。 I want all the tiles to perfectly stack on top of each other, but the tiles on top always go through the tiles below them. 我希望所有的瓷砖完美地堆叠在一起,但顶部的瓷砖总是穿过它们下方的瓷砖。

This is the code: 这是代码:

 var game = new Phaser.Game(700, 700, Phaser.AUTO, 'phaser-demo', { create: create, update: update }); var tiles, textureRegistry = {}; function create() { game.physics.startSystem(Phaser.Physics.ARCADE); game.physics.arcade.gravity.y = 500; tiles = game.add.group(); tiles.physicsBodyType = Phaser.Physics.ARCADE; tiles.enableBody = true; for (var i = 0; i < 10; i++) { for (var j = 0; j < 10; j++) { tiles.add(game.add.sprite(i * 70, j * 70, createBlock(64, 'red'))); } } tiles.setAll('body.collideWorldBounds', true); tiles.setAll('body.bounce', new Phaser.Point(0.5, 0.5)); } function update() { game.physics.arcade.collide(tiles); } function createBlock(size, color) { var name = size + '_' + color; if (textureRegistry[name]) { return textureRegistry[name]; } var bmd = game.add.bitmapData(size, size); bmd.ctx.fillStyle = color; bmd.ctx.fillRect(0, 0, size, size); textureRegistry[name] = bmd; return bmd; } 
 <script src="https://github.com/photonstorm/phaser/releases/download/v2.6.2/phaser.min.js"></script> 

It seems to look even worse on Chrome. 在Chrome上看起来似乎更糟糕。 It's important to note that the problem only occurs when 4x4 or more tiles are used. 重要的是要注意,只有在使用4x4或更多的磁贴时才会出现问题。

Phaser Arcade Physics doesn't handle multi-body contact very well, due to limitations on current version 由于当前版本的限制, Phaser Arcade Physics不能很好地处理多体接触

Alternatively consider using P2 physics instead and/or see discussions below. 或者考虑使用P2物理代替和/或参见下面的讨论。


声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM