-
Notifications
You must be signed in to change notification settings - Fork 3
Your first Project
Hello Goodbye World, because Hello is overrated, you'll be creating a simple Goodbye World
.
Though you'll need a font first, sorry, we (well mostly IceDragon) forgot to package a font with Moon.
From this point on, its assumed you'll be using moon-player
to run and test your projects.
First up you'll need a font, go swipe one off the interwebs, or just grab one from your local font directory or something.
You create a Font object by doing the following:
# signature
font = Moon::Font.new(filename, size)
# usage
font = Moon::Font.new('resources/fonts/Arial.ttf', 18)
Customarily, you'll put all assets/resources in resources/
in a proper sub-directory, but that's just us, feel free to go crazy with uber-tastic-place-to-store-my-assets/things-that-go-on-the-screen/Arial.ttf
, I ain't stopping you.
Font is just a fancy Texture-like class, by itself it renders NOTHING. So to get your Font drawn on the screen, you'll need a Text object.
text = Moon::Text.new(font, "my uber-tastic string!")
Now for a gotcha, if you looked in the bootstrap, you may have noticed that you don't get any methods setup or termination, this may be considered in the future, but for now, just lazy initialize your stuff in #step
, or better yet, write your own bootstrap and share it with us.
in scripts/load.rb
def step(engine, delta)
@text ||= begin
font = Moon::Font.new('resources/fonts/Arial.ttf', 18)
Moon::Text.new(font, "Goodbye, World")
end
@text.render(24, 24, 0)
end
Assuming all went well in the world and your house didn't explode because of a random segfault, you should see 'Goodbye World' in the top left corner of your window, in white.
Easy there, you can have your color, just pass a 3rd parameter to Text on creation.
# signature
text = Moon::Text.new(font, string, options)
# example
text = Moon::Text.new(font, "Goodbye, World", color: Moon::Vector4.new(0, 1, 0, 1))
in scripts/load.rb
def step(engine, delta)
@text ||= begin
font = Moon::Font.new('resources/fonts/Arial.ttf', 18)
Moon::Text.new(font, "Goodbye, World", color: Moon::Vector4.new(0, 1, 0, 1))
end
@text.render(24, 24, 0)
end
Now you must be screaming, "WHERE IS Moon::Color
?" the answer, there is none, there will never be one, get used to it; Moon::Vector4
is now your Moon::Color
.
Congrats you now have a Goodbye World
program in Moon.
Text also accepts a few other options:
Moon::Text.new(font, string,
color: Moon::Vector4, # default: Moon::Vector4.new(1, 1, 1, 1)
outline: Integer, # outline size, 0 will disable outlines, anything higher will create an outline, default: 0
outline_color: Moon::Vector4, # default: Moon::Vector4.new(0, 0, 0, 1)
line_height: Float, # default: 1.2
shader: Moon::Shader, # default: Moon::Shader.default_shader
align: Symbol, # either :left, :right, or :center, default: :left
)