I have a text object in ruby 2D showing score. How do I update the text?
I have this so far
update do
text = Text.new("Score: #{@score}")
end
Instead of replacing it, it is creating a new text object on top of it. How could you replace it instead of adding it on?
Based on docs it seems like you need to instantiate the
Textobject outside of theupdateloop. This will draw it to the screen "forever" until you call theremovemethod.In your current code you are just instantiating a new object every time, and Ruby 2D is secretly keeping it around even though you don't have it assigned to a variable.
Unlike some other 2D libraries like Gosu, Ruby 2D does not stop drawing something until you explicitly tell it to.
Try
Adding and removing objects in Ruby 2D