I have three components, Ground, Block, and Player. I want player to stop falling when coming in contact with both Ground and Block entities. I have tried this.gravity("Ground, Block"); and this.gravity("Ground", "Block"); but the former disables gravity on both components and the latter enables gravity for the first argument.
How can I apply gravity on multiple CraftyJS components?
49 views Asked by Jordan Baron At
1
Use a single component that is added to any that need this functionality. So you could call
this.gravity("Platform"), and then require it for any components that can be stood upon:You don't even need to provide a specific definition for "Platform", since in this case it's just used as a marker component.
An advantage of this approach is that as we create new types of things the player can stand on, we don't have to extend a list in the player object -- we just add the "Platform" component to them as well.