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.
Asked
Active
Viewed 45 times
2
Jordan Baron
- 3,752
- 4
- 15
- 26
1 Answers
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:
Crafty.c("Ground", {
required: "Platform",
init: function(){
// etc
},
});
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.
starwed
- 2,536
- 2
- 25
- 39