Sha256: aaa0d1524dc9d20f56c3c2a6da021fe29e48d1349465c7d6325319b8d4640f93

Contents?: true

Size: 599 Bytes

Versions: 1

Compression:

Stored size: 599 Bytes

Contents

define_behavior :score_keeper do
  requires :backstage, :stage

  setup do
    # TODO helper for "attached subactor"
    label = stage.create_actor(:label, actor.attributes)
    actor.has_attributes label: label, score: 0
    actor.when :position_changed do
      actor.label.x = actor.x
      actor.label.y = actor.y
    end
    actor.when(:remove_me) { label.remove }
    actor.when(:score_changed) { update_text }
    update_text
  end

  helpers do
    def update_text
      actor.label.text = actor.score
    end
  end
end

define_actor :score do
  has_behavior :score_keeper, layered: 999
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gamebox-0.5.0 lib/gamebox/actors/score.rb