Cheat Sheet
This is a lovely little overview of the basics of Taylor, if you’re looking for the full documentation head on over to here.
Index
- Window
- Utility
- Audio
- Keyboard Input
- Mouse Input
- Touch Input
- Gamepad Input
- Vector2
- Rectangle
- Texture2D
- Image
- Font
- Music
- Sound
- Camera2D
- Platform
- Web
- Shader
Window
# Opens a window with width 800 pixels and height 480 pixels.
init_window(800, 480)
# Wrap all your drawing methods in this block.
drawing
do
# Do stuff
end
# Clears the screen with black, defaults to a nice white if no
colour is specified.
clear(colour:
BLACK)
# Closes the window.
close_window
Utility
# Set the framerate we're trying to achieve.
set_target_fps(144)
# Get the current framerate.
get_fps
# Get the amount of time since last frame, also known as the
delta.
get_frame_time
Audio
# Sets up the audio device so we can play music and sounds.
init_audio_device
# Sets the master volume to 80%.
set_master_volume(0.8)
# Closes the audio device, no more music or sound can be played
after this.
close_audio_device
Keyboard Input
# Has the A key been pressed since last frame?
key_pressed?(KEY_A)
# Has the W key been released since last frame?
key_released?(KEY_W)
# Is the space bar being held down?
key_down?(KEY_SPACE)
# Is the enter key not being pressed?
key_up?(KEY_ENTER)
# Returns the key code since last called, call more than once if
there's a queue.
get_key_pressed
# Returns the char code since last called, call more than once if
there's a queue.
get_char_pressed
Mouse Input
# Has the left mouse button been pressed since last frame?
mouse_button_pressed?(MOUSE_LEFT_BUTTON)
# Has the right mouse button been released since last frame?
mouse_button_released?(MOUSE_RIGHT_BUTTON)
# Is the middle mouse button being held down?
mouse_button_down?(MOUSE_MIDDLE_BUTTON)
# Is the middle mouse button not being pressed?
key_up?(MOUSE_MIDDLE_BUTTON)
# Returns a vector with the current position of the mouse cursor.
get_mouse_position
# Sets the mouse cursor position to 25, 50.
set_mouse_position(25, 50)
# Gets how much the mouse wheel has moved.
get_mouse_wheel_move
Touch Input
# Returns a vector with the current touch position.
get_touch_position
Gamepad Input
# Is the gamepad at the specified index available?
gamepad_available?(0)
# Gets the name of the gamepad at the specified index.
get_gamepad_name(0)
# Has the top right side button (EG: Y or triangle) been pressed since last frame?
gamepad_button_pressed?(0, GAMEPAD_BUTTON_RIGHT_FACE_UP)
# Has the left trigger been released since last frame?
gamepad_button_released?(0, GAMEPAD_BUTTON_LEFT_TRIGGER_2)
# Is the middle right button (EG: start) being held down?
gamepad_button_down?(0, GAMEPAD_BUTTON_MIDDLE_RIGHT)
# Is the left thumbstick not being pressed?
gamepad_button_up?(0, GAMEPAD_BUTTON_LEFT_THUMB)
# How many joysticks does the specified gamepad have?
get_gamepad_axis_count(0)
# Get the movement from the left joystick for the specified
gamepad.
get_gamepad_axis_movement(0, 0)
Vector2
# Creates a vector with at position 20, 20
vector = Vector2.new(20, 20)
# Where on the x axis is the vector in pixels?
vector.x
# Where on the y axis is the vector in pixels?
vector.y
Rectangle
# Creates a new rectangle at position 10, 10 with width 50 and
height 80.
rectangle = Rectangle.new(10, 10, 50, 80)
# Where on the x axis is the rectangle in pixels?
rectangle.x
# Where on the y axis is the rectangle in pixels?
rectangle.y
# How many pixels wide is the rectangle?
rectangle.width
# How many pixels tall is the rectangle?
rectangle.height
# Draw the rectangle in black.
rectangle.draw(colour:
BLACK)
# Draw the outline of the rectangle in black.
rectangle.draw(outline:
true, colour:
BLACK)
# Draw the rectangle in black with rounded corners.
rectangle.draw(rounded:
true, radius:
0.25, colour:
BLACK)
# Draw the outline of the rectangle in black with rounded corners.
rectangle.draw(outline:
true, rounded:
true, radius:
0.25, colour:
BLACK)
Texture2D
# Load the texture from ./assets/cool.png.
texture = Texture2D.load("./assets/cool.png")
# How many pixels wide is the texture?
texture.width
# How many pixels tall is the texture?
texture.height
# Draw the texture to the Rectangle's position and size.
texture.draw(destination:
rectangle)
# Draw the texture rotated 90 degrees clockwise.
texture.draw(destination:
rectangle, rotation:
90)
# Generates mipmaps for
the texture.
texture.generate_mipmaps
# When drawing the texture, use this filter.
texture.filter = TEXTURE_FILTER_BILINEAR
# Unload the texture from memory, you will no longer be able to
draw it.
texture.unload
Image
# Load the image from ./assets/cool.png.
image = Image.load("./assets/cool.png")
# Generates a 128x64 image full of white pixels.
image = Image.generate(width:
128, height:
64, colour:
WHITE)
# How many pixels wide is the image?
image.width
# How many pixels tall is the image?
image.height
# Saves the image to output.png.
image.export("./output.png")
# Copies the specified region into a new image, if source is not
defined it copies the whole image.
different_image = image.copy(source:
Rectangle.new(0,0,10,10))
# Converts the image to a Texture2D
image.to_texture
# Scales the image to be the specified size.
image.resize!(width:
256, height:
128)
# Crops the image to the specified Rectangle.
image.crop!(Rectangle.new(0,0,64,32))
# Applies the specified alpha mask to the image.
image.alpha_mask
=
Image.load("./alpha.png")
# Flips the image horizontally.
image.flip_horizontal!
# Flips the image vertically.
image.flip_vertical!
# Rotates the image 90 degrees in the specified direction. (:cw
for clockwise and :ccw for counter-clockwise)
image.rotate!(:ccw)
# Tints the image with the specified colour.
image.tint!(BLUE)
# Inverts all the colours in the image.
image.invert!
# Changes all the colours in the image to grayscale.
image.grayscale!
# Changes the contrast in the image, must be between -100 and
100.
image.contrast!(10)
# Changes the brightness in the image, must be between -255 and
255.
image.brightness!(50)
# Changes all GREEN in the image to BLUE.
image.replace!(GREEN, BLUE)
# Unload the image from memory.
image.unload
Font
# Load the font from ./assets/neat.ttf.
font = Font.load("./assets/neat.ttf")
# When drawing the font, use this filter.
font.filter = TEXTURE_FILTER_BILINEAR
# Draws "Hello" at the vector position at size 16 and red.
font.draw("Hello", position:
vector, size:
16, colour:
RED)
# Returns a Vector2 with the width and height of the rendered
text as x and y respectively.
font.measure("Hello", size:
16)
# Returns an image of "G'day" in size 16 font and violet.
font.to_image("G'day", size:
16, colour:
VIOLET)
# Unloads the font from memory. It can no longer be used to draw
text.
font.unload
Music
# Load the music from ./assets/cool_song.mp3.
music = Music.load("./assets/cool_song.mp3")
# Starts the playback of the music.
music.play
# Updates the music stream, this must be called every game loop.
music.update
# Stops the music playing, you need to call music.play to start
it again.
music.stop
# Pauses the music from playing, you need to call music.resume to start
it again.
music.pause
# Resumes paused music.
music.resume
# Is the music currently playing?
music.playing?
# How long is the music?
music.length
# How long has the music been playing?
music.played
# Sets the volume of the music, must be between 0 and 1 inclusive.
music.volume
=
0.8
# Sets the pitch of the music.
music.pitch
=
1.2
# Unloads the music from memory. It can no longer be played.
music.unload
Sound
# Load the sound from ./assets/jump.mp3.
sound = Sound.load("./assets/jump.mp3")
# Starts the playback of the sound.
sound.play
# Sets the volume of the sound, must be between 0 and 1 inclusive.
sound.volume
=
0.8
# Sets the pitch of the sound.
sound.pitch
=
1.2
# Stops all currently playing sounds.
Sound.stop
# How many sounds are currently playing?
Sound.playing
# Unloads the sound from memory. It can no longer be played.
sound.unload
Camera2D
# Creates a new camera object with no rotation and no zoom.
camera = Camera2D.new(Vector2::ZERO, Vector2::ZERO, 0, 1)
# Sets the camera target to be 160 pixels along the x axis.
camera.target.x
=
160
# Sets the camera target to be 120 pixels along the y axis.
camera.target.y
=
120
# Sets the camera offset to be 30 pixels along the x axis.
camera.offset.x
=
30
# Sets the camera offset to be 40 pixels along the y axis.
camera.offset.y
=
40
# Wrap all your drawing methods in this block and it will be
rendered as though viewed through the camera.
camera.drawing
do
# Do stuff
end
# Takes a vector with world coordinates and translates it to what
it would be if viewed through the camera.
camera.convert_to_camera_position(Vector2::ZERO)
# Takes a vector with camera coordinates and translates it to
what it would be in the world.
camera.convert_to_world_position(Vector2::ZERO)
Platform
# Is this a released version of the game?
released?
# Are we running in the browser?
browser?
# Are we running on a Linux computer?
linux?
# Are we running on a Windows computer?
windows?
# Are we running on an OSX computer?
osx?
Web
These methods are only available when running a web exported game.
# For web exports we use this method to set the main loop since
infinite loops would run forever and never render due to the single threaded
nature of browsers.
set_main_loop('main')
# Sets the key 'my_key' in LocalStorage in the browser to 'value'.
LocalStorage.set_item('my_key', 'value')
# Gets the key 'my_key' from LocalStorage in the browser.
LocalStorage.get_item('my_key')
Shader
# Load the fragment shader from './assets/shaders/fragment_330.fs'
on desktop and './assets/shaders/fragment_100.fs' in the browser.
shader = Shader.load(fragment_shader_path:
"./assets/shaders/fragment_#{GLSL_VERSION}.fs")
# Is the shader ready to be used yet?
shader.ready?
# Sets the variable 'red' inside the shader program to be 0.75.
shader.set_value(value:
0.75, variable:
red)
# Renders everything inside with the shader applied.
shader.draw
do
# Do stuff
end
# Unloads the shader from memory.
shader.unload