- Contents:
- General
- Draw parameters
- Draw operations
- Palette
- Surfaces
- Sprites
- Text rendering
- Screen size and render modes
screen_size()
screen_w()
screen_h()
screen_scale()
screen_render_stretch(enable)
screen_render_integer_scale(enable)
screen_resizeable(enable, scale, on_resize_callback)
screen_resize(w, h, resize_window)
update_screen_size()
screen_get_render_stretch()
screen_get_render_integer_scale()
screen_get_resizeable()
set_background_color(c)
window_size(w, h)
- Post-processing shader
- Initializes the gfx subsystem of Sugar.
- Is called by
init_sugar(...)
. w
andh
are the width and height you want for your simulated screen resolution.scale
is the scale factor you want for stretching your simulated resolution. You can change the behavior around scaling with the varioussugar.gfx.screen_...
functions.
- Shuts down the gfx subsystem.
- Is called by
sugar.shutdown_sugar ()
.
- Shows the result of your draw operations on the screen.
- Is called automatically around
love.draw ()
.
- If set,
canvas
has to be a love2D canvas, built withlove.graphics.newCanvas(...)
. - If
canvas
is set, sugarlove will draw the simulated screen to this love2D canvas instead of directly to the real screen. - This can be used in pair with the
sugar.after_render
callback to do post-processing on sugarlove's output.
- Sets a coordinate offset of {-x, -y} for the following draw operations.
- Calling
camera ()
resets this.
- Offsets the coordinate offset so that it becomes {-x-dx, -y-dy}
- Gets the current (inversed) drawing coordinate offset.
- Returns:
- camera_x
- camera_y
- Sets the clip area so that nothing gets drawn outside of it.
- Gets the current clip area.
- Returns:
- clip_x
- clip_y
- clip_w
- clip_h
- Sets the color to use for drawing functions to
i
. i
is an index to a color in the currently used palette.
- Swaps the color
ca
with the colorcb
in the following draw operations. (ifflip_level
isfalse
) ca
andcb
are both indexes in the currently used palette.- If
flip_level
is true, the swap will only take effect on display.
- Makes the color
c
transparent or not, for sprite operations. c
is an index in the currently used palette.0
is transparent by default. Usepalt(0, false)
for the color0
to be drawn from sprites.
- Clears the screen with the color
c
.
- Alias for
clear(c)
.
- Draws a filled rectangle.
- Draws an empty rectangle.
- Draws a filled circle.
- Draws an empty circle.
- Draws a filled triangle.
- Draws an empty triangle.
- Draws a line.
- Sets the Color of one pixel.
- Gets the palette index of the pixel at {x; y} on the screen.
- Changes made to the screen will not be reflected until you call
scan_surface()
.
- Sets the given palette as palette to use.
- The palette has to be a table of hexadecimal colors. (e.g. 0xff00ff)
- Can be used with the pre-defined palettes in
palettes
.
- Returns a copy of the palette in use.
- Returns the length of the currently used palette.
- A table containing pre-defined palettes.
- The default palette of Sugarcoat is
palettes.kirokaze_gb
- Here are the palettes contained:
palettes. kirokaze_gb
palettes. gb_chocolate
palettes. black_zero_gb
palettes. pokemon_gb
palettes. blessing
palettes. oil6
palettes. nyx8
palettes. equpix15
palettes. pico8
palettes. sweetie16
palettes. grunge_shift
palettes. bubblegum16
palettes. mail24
palettes. arcade29
palettes. ufo50
palettes. famicube
palettes. aap_splendor128
- Creates a surface with a width of
w
and a height ofh
. - The surface can be used in the other surface functions with its key.
- If
key
is not set, key is the next available numeral key. - Returns the surface's key.
- Loads the file
file_name
as a new surface. - The file will be converted to an indexed surface using the
palette
. Ifpalette
isn't set, the currently used palette will be used. - The surface becomes the new spritesheet if
use_as_spritesheet
is true. - The program will crash if
file_name
cannot be found. - If used in Castle,
file_name
may be an URL to a picture hosted online.
- Deletes the surface
key
. (duh.)
- Returns:
- width of the surface
- height of the surface
- Returns
true
if there is a surface forkey
, returnsfalse
otherwise.
- Saves the surface
surf_key
, upscaled byscale
, asfile_name
, as a PNG. - The picture will be saved locally, at
%appdata%\LOVE\[project (or Castle)]
if on Windows, and at/Users/user/Library/Application Support/LOVE/[project (or castle)]
if on Mac. - If
surf_key
isnil
, saves the screen surface.
- Returns an ImageData representing the surface
surf_key
, upscaled byscale
. - If
surf_key
isnil
, it uses the screen surface instead. - ImageData is a Love2D data type.
- Sets the target of the following draw operations to that surface.
target()
resets it.
- Returns the key of the currently used target.
- If the current target is the screen, this will return
__screen__
.
- Returns:
- width of the current target
- height of the current target
- Returns the width of the current target.
- Returns the height of the current target.
- Updates the pixel info to be querried with
pget(...)
andsget(...)
. - If
surf_key
is set, updates the info for the surfacesurf_key
. - If
surf_key
isn't set, updates the info for the screen surface. - This function can be slow. Avoid using it more than a few times per frame.
Note that the spritesheet drawing functions will fail if no spritesheet surface was set.
- Use the surface
surf_key
as spritesheet.
- Get the key for the current spritesheet.
- Sets the tile size to use for the spritesheet's grid.
- Default tile size is 8x8.
- Returns:
- the grid's tile width
- the grid's tile height
- Draws the sprite at the position
s
on the spritesheet grid, at the coordinates {x; y} w
andh
are the size of the sprite in tiles.- If
flip_x
is true, flips the sprite horizontally - If
flip_y
is true, flips the sprite vertically
- Draws the sprite at the position
s
on the spritesheet grid, at the coordinates {x; y}, with the rotationa
. ('a' is a turn-based angle) w
andh
are the size of the sprite in tiles.anchor_x
andanchor_y
define the rotation point of the sprite. {0; 0} is upper-left corner, {1; 1} is down-right corner.scale_x
andscale_y
are scale factors.
- Draws and stretches the rectangle {sx, sy, sw, sh} from the sprite-sheet as the rectangle {dx, dy, dw, dh} on the target surface.
- Draws the entire surface
key
at the coordinates {x; y}. - If
key
isnil
, draws the current spritesheet instead. - If
dw
anddh
are set, resizes the surface to that size.
- Gets the palette index of the pixel at {x; y} on the spritesheet.
- If
surf_key
is set, gets the pixel from the surfacekey
instead. - Changes made to the surface will not be reflected by
sget(...)
until you callscan_surface(surf_key)
.
The default font in Sugarcoat and sugarlove is TeapotPro by Eeve Somepx! Support him!
- Loads the font from the file at
ttf_filepath
. - If you're unsure about the size, try 16 or 12.
- If
key
is not set, key is the next available numeral font key. - If
use_it
is true, the loaded font becomes the active font. - The program will crash if
ttf_filepath
cannot be found.
- Deletes the font
key
. (duh.)
- Sets the font
key
as current active font.
- Returns the key for the current active font.
- Returns the width in pixels of the string
str
as displayed with the fontfont
. - Font defaults to the current active font.
- Draws the string
str
on the screen at the coordinates {x; y}.
- Defines the print pattern for
pprint(...)
. - This function should be called like this:
printp( 0x1200,
0x2300,
0x0000,
0x0000 )
a, b, c, d
represent the four lines of the pattern, with each hexadecimal number being a cell of the pattern.- The hexadecimal number defines the viewing priority: 1 will always be visible, 2 may be hidden by 1 but not by 3, 3 may be hidden by 1 and 2, 0 will not be drawn.
- The position of those numbers on the grid defines the offset with which they should be drawn.
- Those numbers also correspond to the colors you set with
printp_color(c1, c2, c3)
. - With the example above,
pprint(text, x, y)
will rendertext
atx+1, y+1
with color 3, then atx+1, y
andx, y+1
with color 2, and finally atx, y
with color 1.
- Sets the colors for
pprint(...)
.
- Renders the string
str
with the pattern defined by the lastprintp(...)
call, at the coordonatesx, y
. c1, c2, c3
are optional, you may callprintp_color(c1, c2, c3)
beforehand instead.
- Returns:
- the width of the simulated screen resolution
- the height of the simulated screen resolution
- Returns the width of the simulated screen resolution
- Returns the height of the simulated screen resolution
- Returns the scale of the simulated resolution to be rendered on the actual screen.
- Sets whether the simulated screen should be stretched to fill the entire game window.
- Only in this mode may the width and height factors not be the same.
- Sets whether to only use integer factors to stretch the simulated screen.
- Sets whether the simulated resolution should change according to the window size.
- The new resolution will always be [window_size /
scale
]. on_resize_callback
is a function to be called on resizing. Alternatively, you may definelove.resize()
.
- Resizes the simulated resolution to the given size.
- Updates the screen rendering after window changes.
- Should get called internally whenever necessary.
- Returns whether the render stretch is enabled.
- Returns whether the render integer scale is enabled.
- Returns whether the simulated screen is resizeable.
- Changes the window color around the simulated screen to the color
c
in the palette. - If
c
isn't set, the window color is set to black. (#000000)
- If
w
andh
are set, resizes the window to that size. - In any case, returns:
- the width of the window
- the height of the window
- Attempts to compile the string
shader_code
as a GLSL ES shader. - If compiled successfully, the shader is used to render the simulated screen onto the actual full-size screen.
- If the compilation failed, an error will be shown in the log, along with why it failed.
- In your shader code, you can use the following functions and variables:
Texel_color(Image texture, vec2 coords)
returns the texture's color at those coordinates. You should use this function instead ofTexel(...)
because the latter will return encoded values.Texel_index(Image texture, vec2 coords)
returns the palette index for the color at those coordinates, as anint
.SCREEN_SIZE
is avec2
containing the width and the height of the simulated screen.PALETTE
is an array ofvec4
, containing the colors of the palette.SWAPS
is an array ofint
containing the palette swaps made at flip level.
- If
shader_code
is not set, this will reset to the default rendering shader.
- Feeds data into
extern
variables in the current screen shader. - For each key in
value_table
, if a correspondingextern
variable exists in the shader, it will receive the corresponding value. - Both array values and vector values should be passed as list-style tables.
- Surfaces can be passed as Image variables in the shader.
value_table
has to be defined as a table such as this:
{
[key_A] = value,
[key_B] = {array_v1, array_v2, ...},
[key_C] = {vec_x, vec_y, vec_z},
...
}