I'm diving into GameplayKit with Spritekit and from what I gather, you subclass GKEntity
and then start adding GKComponents
to that entity. The entity would more or less just be a bag of components that fill some function.
The part I'm confused about is communication between components. How do you keep them decoupled. For example, lets say I have a HealthComponent
class, and I add that component to a PlayerEntity
, and an EnemyEntity
. I also have a HealthBarComponent
but I only want a health bar to appear above the player. When the player takes damage, that information needs to be updated in the HealthBarComponent
.
So how should that information be sent? I see there is a class called GKComponentSystem
in the documentation. I'm not 100% on how that should be used.
Another question is.. when the player's health reaches zero he should regenerate while the enemy should stay dead. When the player runs out of lives, the game ends.
The health system for both an enemy and player would be roughly the same, but the events around death would be totally different for each. I'm not following how to use a component system while keeping the unique behavior of each entity.
some pseudo-code would be great
ChargeComponent
which notifies its delegate when charge is lost. The game also has a similar mechanic to the health regeneration one you mentioned, which was implemented using aGKStateMachine
and accompanying states. – Align