2

我有三个组件,GroundBlockPlayerGround我希望玩家在与Block实体接触时停止跌倒。我已经尝试过this.gravity("Ground, Block");this.gravity("Ground", "Block");但前者禁用了两个组件的重力,而后者启用了第一个参数的重力。

4

1 回答 1

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.

于 2018-05-03T23:30:54.190 回答