Class: PopupText

Inherits:
Chingu::GameObject
  • Object
show all
Defined in:
lib/prkwars/popuptext.rb

Overview

Class used for messages that pop up on the screen whenever something relevant happens - e.g. score goes up.

Instance Method Summary collapse

Constructor Details

#initialize(message, x, y, options = {}) ⇒ PopupText

Initialization method for PopupText requires x, y to determine where the message gets spawned on the screen.



13
14
15
16
17
# File 'lib/prkwars/popuptext.rb', line 13

def initialize(message, x, y, options = {})
  super(options)

  @msg = Chingu::Text.create(message, x: x, y: y, size: 30)
end

Instance Method Details

#updateObject

Updating the popuptext changes the y coordinate and slowly fades the message out.



22
23
24
25
26
# File 'lib/prkwars/popuptext.rb', line 22

def update
  @msg.y -= 1
  @msg.color.alpha -= 4
  @msg.destroy! if color.alpha.zero?
end