Make objects inside a group collide with themselves in Phaser.io?

时光总嘲笑我的痴心妄想 提交于 2019-12-07 20:17:55

问题


This question is regarding phaser.io. Can someone show me how to make objects inside a group collide with each other. Right now when i do,

//board is the group and it has many elements
//Floor is where all the elements fall to
game.physics.arcade.collide(this.board, this.floor);

All the elements inside the group stack on top of each other when they hit the floor at the same position. In other words the stack builds at one position, the latest one hiding the previous element and not upwards in the sense one on top of another at a higher position. How can i make the stack build upwards? If you could just show me how to make elements inside a group collide would be great. Thanks.


回答1:


You can collide a Group with itself:

game.physics.arcade.collide(this.board, this.board);

Although on that note I would point you at this tutorial on adding a simple 1d sort array, which will help considerably if the Group is densely populated: http://ra3s.com/wordpress/dysfunctional-programming/pruning-collision-detection-with-a-1d-sort/



来源:https://stackoverflow.com/questions/28391544/make-objects-inside-a-group-collide-with-themselves-in-phaser-io

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!