Love2D Nine and Three Slice

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
Hipreme
Prole
Posts: 15
Joined: Wed Jun 03, 2020 9:57 pm
Contact:

Love2D Nine and Three Slice

Post by Hipreme »

Hello again guys, this time I have created another lib, it is very efficiet as it is using the spritebatch feature, and the better, it is simple as:

Code: Select all

window = NineSlice.generateFromRect(gTexture, 0,0, 196, 196)
window:set(0, 0, width, height, useMinimumWidth, useMinimumHeight)
function love.draw()
  window:render()
end
NineSlice:
If you prefer, you can pass the 9 quads directly in the constructor, it will allow any size:

Code: Select all

NineSlice(gTextures['ui'],
    love.graphics.newQuad(x, y, w, h, gTextures['ui']:getDimensions()),
    love.graphics.newQuad(x, y, w, h, gTextures['ui']:getDimensions()),
    love.graphics.newQuad(x, y, w, h, gTextures['ui']:getDimensions()),
    love.graphics.newQuad(x, y, w, h, gTextures['ui']:getDimensions()),
    love.graphics.newQuad(x, y, w, h, gTextures['ui']:getDimensions()),
    love.graphics.newQuad(x, y, w, h, gTextures['ui']:getDimensions()),
    love.graphics.newQuad(x, y, w, h, gTextures['ui']:getDimensions()),
    love.graphics.newQuad(x, y, w, h, gTextures['ui']:getDimensions()),
    love.graphics.newQuad(x, y, w, h, gTextures['ui']:getDimensions()))
So, you have the option for passing each quad of any size, generating it from a rectangle, or passing tile width and height with offsets:

Code: Select all

NineSlice.generateFromTiles(texture, startX, startY, tileWidth, tileHeight, offset_Per_Tile_X, offset_Per_Tile_Y,)
Three Slice:
Using it is very similar, the only difference is that the constructor receives 3 quads instead of 9, and it receives one additional parameter for knowing if it is the horizontal or the vertical type:

Code: Select all

ThreeSlice.generateFromTiles(texture, startX, startY, tileWidth, tileHeight, offset_Per_Tile_X, offset_Per_Tile_Y, isHorizontal)
If you pass it from a rectangle, it is predicted if it is horizontal or vertical type by its size

Code: Select all

ThreeSlice.generateFromRect(texture, x, y, w, h)
Remember that you always need to set its size after generating it:

Code: Select all

ThreeSlice:set(x,y, width, height, useMinimum)
The use minimum optional parameter will clamp its height if horizontal or width if vertical, for non-stretching purposes

Download it at: https://github.com/MrcSnm/Love2D-Nine-and-Three-Slices


Here is the comparison between original image and 9 and 3-Slices
Attachments
ui.png
ui.png (2.4 KiB) Viewed 11331 times
nine_three_slice.gif
nine_three_slice.gif (106.58 KiB) Viewed 11331 times
Post Reply

Who is online

Users browsing this forum: No registered users and 80 guests