mikewesthad / phaser-matter-collision-plugin

A plugin for making it easier to manage collisions with Phaser 3 + Matter.js
MIT License
99 stars 8 forks source link

Params instead of single object for all methods? #4

Closed mktcode closed 4 years ago

mktcode commented 4 years ago

Hey! Thanks for this handy little plugin!

Juuuuust one thing.... Can't you make all functions take parameters like the addOnCollide instead of an object with key-value pairs?

I just prefer this

this.matterCollision.addOnCollideStart(player, trapDoor, () => console.log("Player touched door!"));

over this

this.matterCollision.addOnCollideStart({
  objectA: player,
  objectB: trapDoor,
  callback: () => console.log("Player touched door!")
});

It's also more like everything else in Phase.

mikewesthad commented 4 years ago

Howdy. Glad you found it helpful. The idea with objects as parameters is that it is easier to omit the optional parameters. objectB and context are optional, so rather than writing the confusing line to detect when any other object hits the player:

addOnCollideStart(player, undefined, () => console.log("Something collided with player"))

You get the more explicit:

addOnCollideStart({ objectA: player, callback: () => console.log("Something collided with player") })

addOnCollide is private and not really intended to be used outside of the library's internal code.

Re: Phaser's methods. Many of them use objects as arguments, e.g. every method under the GameObjectCreator. The methods here different from the arcade physics collider API because the functionality is different - you can't have an A vs everything collider there.

You can easily patch in your preferred way of consuming the plugin, e.g. something like:

// Not tested, should be approximately right
matterCollision.addOnCollideStartCustom = function (objectA, objectB, callback, context) {
    this.addOnCollideStart({ objectA, objectB, callback, context });   
}
mktcode commented 4 years ago

Thanks for you reply. In the end I guess... it's not that much of a deal! :smiley: Thanks again for the plugin! Very useful! Same as https://github.com/mikewesthad/dungeon btw. I'm using that as well. You can see a very early prototype of my game here: https://mktcode.itch.io/infinite-dungeons I will now investigate the code to see if I can make some changes to allow me to determine a few fixtures for rooms like "at least one room with only one door".

mikewesthad commented 4 years ago

Cool! Stanley parable vibes.

mktcode commented 4 years ago

A little bit, yes. A mix between that and a diablo-like dungeon crawler is what I have in mind.

mktcode commented 4 years ago

Hey... do you have discord or something and a minute or two? I could really need a little help with matter.js. It's confusing the shit out of me and feel a bit stuck.