Commit f99f182
committed
Arcade Physics is now using a spacial pre-sort for all Sprite vs. Group and Group vs. Group collisions. You can define the direction the sort will prioritise via the new
There are 3 other directions available (`RIGHT_LEFT`, `TOP_BOTTOM` and `BOTTOM_TOP`) and which one you need will depend on your game type. If you were making a vertically scrolling shoot-em-up then you'd pick `BOTTOM_TOP` so it sorts all objects above and can bail out quickly.
More importantly you can switch the `sortDirection` at run-time with no loss of performance. Just make sure you do it *before* running any collision checks. So if you had a large 8-way scrolling world you could set the `sortDirection` to match the direction the player was moving in and adjust it in real-time, getting the benefits as you go. My thanks to Aaron Lahman for inspiring this update.sortDirection property. By default it is set to Phaser.Physics.Arcade.LEFT_RIGHT. For example if you are making a horizontally scrolling game, where the player starts on the left and moves to the right, then this sort order will allow the physics system to quickly eliminate any object to the right of the players bounds. This cuts down on the sheer volume of actual collision checks needing to be made. In a densely populated level it can improve fps rate dramatically.1 parent 74eeddf commit f99f182
2 files changed
Lines changed: 99 additions & 47 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
63 | | - | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
64 | 78 | | |
65 | 79 | | |
66 | 80 | | |
| |||
86 | 100 | | |
87 | 101 | | |
88 | 102 | | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | 103 | | |
94 | 104 | | |
95 | 105 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
| 60 | + | |
60 | 61 | | |
61 | 62 | | |
62 | 63 | | |
| |||
75 | 76 | | |
76 | 77 | | |
77 | 78 | | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | 79 | | |
84 | 80 | | |
85 | 81 | | |
| |||
95 | 91 | | |
96 | 92 | | |
97 | 93 | | |
98 | | - | |
| 94 | + | |
99 | 95 | | |
100 | 96 | | |
101 | 97 | | |
102 | 98 | | |
103 | 99 | | |
104 | 100 | | |
105 | 101 | | |
106 | | - | |
| 102 | + | |
107 | 103 | | |
108 | 104 | | |
109 | 105 | | |
110 | 106 | | |
111 | 107 | | |
112 | 108 | | |
113 | 109 | | |
114 | | - | |
| 110 | + | |
115 | 111 | | |
116 | 112 | | |
117 | 113 | | |
118 | 114 | | |
119 | 115 | | |
120 | 116 | | |
121 | 117 | | |
122 | | - | |
| 118 | + | |
123 | 119 | | |
124 | 120 | | |
125 | 121 | | |
| |||
643 | 639 | | |
644 | 640 | | |
645 | 641 | | |
646 | | - | |
647 | | - | |
648 | | - | |
649 | | - | |
650 | 642 | | |
651 | 643 | | |
652 | 644 | | |
| |||
658 | 650 | | |
659 | 651 | | |
660 | 652 | | |
661 | | - | |
| 653 | + | |
662 | 654 | | |
663 | | - | |
664 | | - | |
| 655 | + | |
665 | 656 | | |
666 | | - | |
| 657 | + | |
667 | 658 | | |
668 | | - | |
669 | | - | |
| 659 | + | |
670 | 660 | | |
671 | 661 | | |
672 | 662 | | |
673 | 663 | | |
674 | | - | |
| 664 | + | |
675 | 665 | | |
676 | | - | |
677 | | - | |
| 666 | + | |
678 | 667 | | |
679 | | - | |
| 668 | + | |
680 | 669 | | |
681 | | - | |
682 | | - | |
| 670 | + | |
683 | 671 | | |
684 | 672 | | |
685 | 673 | | |
686 | 674 | | |
687 | | - | |
| 675 | + | |
688 | 676 | | |
689 | | - | |
690 | | - | |
| 677 | + | |
691 | 678 | | |
692 | | - | |
| 679 | + | |
693 | 680 | | |
694 | | - | |
695 | | - | |
| 681 | + | |
696 | 682 | | |
697 | 683 | | |
698 | 684 | | |
699 | 685 | | |
700 | | - | |
| 686 | + | |
701 | 687 | | |
702 | | - | |
703 | | - | |
| 688 | + | |
704 | 689 | | |
705 | | - | |
| 690 | + | |
706 | 691 | | |
707 | | - | |
708 | | - | |
| 692 | + | |
709 | 693 | | |
710 | 694 | | |
711 | 695 | | |
712 | | - | |
713 | 696 | | |
714 | 697 | | |
715 | 698 | | |
| |||
760 | 743 | | |
761 | 744 | | |
762 | 745 | | |
763 | | - | |
| 746 | + | |
764 | 747 | | |
765 | | - | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
766 | 757 | | |
767 | | - | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
768 | 779 | | |
769 | | - | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
770 | 788 | | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
771 | 813 | | |
772 | 814 | | |
773 | 815 | | |
| |||
0 commit comments