simple-slider

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
georgeprosser
Citizen
Posts: 68
Joined: Fri Mar 28, 2014 5:55 pm

simple-slider

Post by georgeprosser »

Hiya lovers!

I made a tiny library that lets you easily put basic sliders in your game. It gives you customizable sliders that can manipulate properties, like audio volume.

Image

Image

Image

Example

Code: Select all

require 'simple-slider'

function love.load()
    music = love.audio.newSource('music.ogg')
    music:play()

    -- create a new slider
    volumeSlider = newSlider(400, 300, 300, 0.5, 0, 1, function (v) love.audio.setVolume(v) end)
end

function love.update(dt)
    -- update slider, must be called every frame
    volumeSlider:update()
end

function love.draw()
    love.graphics.setBackgroundColor(249, 205, 173)

    love.graphics.setLineWidth(4)
    love.graphics.setColor(254, 67, 101)

    -- draw slider, set color and line style before calling
    volumeSlider:draw()
end
Usage
Download simple-slider.lua and place it in your game directory. Make sure to require it.

Code: Select all

require 'simple-slider'
Create a new slider by using newSlider, which will return a slider object.

Code: Select all

slider = newSlider(x, y, length, value, min, max, setter, style)

    -- x: x position of center of slider
    -- y: y position of center of slider
    -- length: length of slider track
    -- value: initial value for property
    -- min: minimum value for property
    -- max: maximum value for property
    -- setter: function called when slider is updated, supplied with current slider value
    -- style: optional table of style flags
        -- width: width of knob, defaults to 0.1 of slider length
        -- orientation: 'horizontal' or 'vertical', defaults to 'horizontal'
        -- track: track style, 'rectangle' or 'roundrect' or 'line', defaults to 'rectangle'
        -- knob: knob style,  'rectangle' or 'circle', defaults to 'rectangle'
Update the slider every frame

Code: Select all

slider:update()

-- or optionally

slider:update(mouseX, mouseY, mouseDown)

-- (this allows you to supply your own parameters for mouse position and state - useful if your draw calls are being offset, or you want to use a controller for input)
Draw the slider, setting any draw options like color or line width just before

Code: Select all

slider:draw()
If necessary you can access the value held by the slider

Code: Select all

slider:getValue()
Have a look at the demo if you want to see some more code examples.

Download
simple-slider.lua
(4.85 KiB) Downloaded 756 times
demo.love
(1.88 MiB) Downloaded 463 times
Last edited by georgeprosser on Sun Aug 28, 2016 7:47 am, edited 5 times in total.
NowakHDZ
Prole
Posts: 8
Joined: Tue Aug 04, 2015 8:53 pm

Re: simple-slider

Post by NowakHDZ »

Very cool! Very simple and very nice! I wonder if I could use it for my game, for free? At what condition?
Thank you in advance, keep it up! :awesome:
User avatar
georgeprosser
Citizen
Posts: 68
Joined: Fri Mar 28, 2014 5:55 pm

Re: simple-slider

Post by georgeprosser »

NowakHDZ wrote:I wonder if I could use it for my game, for free?
Absolutely! I'm releasing this so that other people can use it, modify it, redistribute it etc.

Free, no credit needed.
User avatar
Ranguna259
Party member
Posts: 911
Joined: Tue Jun 18, 2013 10:58 pm
Location: I'm right next to you

Re: simple-slider

Post by Ranguna259 »

georgeprosser wrote:Absolutely! I'm releasing this so that other people can use it, modify it, redistribute it etc.

Free, no credit needed.
I suggest using CC BY license (human-readable summary). Link it in you code ( or on this thread and link this thread in your code).
LoveDebug- A library that will help you debug your game with an on-screen fully interactive lua console, you can even do code hotswapping :D

Check out my twitter.
User avatar
georgeprosser
Citizen
Posts: 68
Joined: Fri Mar 28, 2014 5:55 pm

Re: simple-slider

Post by georgeprosser »

Ranguna259 wrote:I suggest using CC BY license (human-readable summary). Link it in you code ( or on this thread and link this thread in your code).
I'm clueless about licensing. Is it necessary?
User avatar
qubodup
Inner party member
Posts: 775
Joined: Sat Jun 21, 2008 9:21 pm
Location: Berlin, Germany
Contact:

Re: simple-slider

Post by qubodup »

Very nice demo, fun to play around with! :crazy:

http://youtu.be/hlWzLV1yMH4
lg.newImage("cat.png") -- made possible by lg = love.graphics
-- Don't force fullscreen (it frustrates those who want to try your game real quick) -- Develop for 1280x720 (so people can make HD videos)
User avatar
Ranguna259
Party member
Posts: 911
Joined: Tue Jun 18, 2013 10:58 pm
Location: I'm right next to you

Re: simple-slider

Post by Ranguna259 »

georgeprosser wrote:I'm clueless about licensing. Is it necessary?
People feel more secure when they use stuff that has been properly licensed. CC BY is probably the best license for what you want, it allows anyone to use you library however they want as longs as they give you credit. You can opt not use any license, we trust that you won't trick use in any legal way.. But at least read a little on the web about open source license, they are great.
LoveDebug- A library that will help you debug your game with an on-screen fully interactive lua console, you can even do code hotswapping :D

Check out my twitter.
User avatar
qubodup
Inner party member
Posts: 775
Joined: Sat Jun 21, 2008 9:21 pm
Location: Berlin, Germany
Contact:

Re: simple-slider

Post by qubodup »

Ranguna259 wrote:CC BY
@georgeprosser Don't use it for software.

What you should actually so that people can use this for LÖVE projects without hassle is put LÖVE's license.txt in your project, delete everything except lines 3-22 and replace the now-first line with the current year and your name. You can put a link or email address there as well if you like.
lg.newImage("cat.png") -- made possible by lg = love.graphics
-- Don't force fullscreen (it frustrates those who want to try your game real quick) -- Develop for 1280x720 (so people can make HD videos)
User avatar
georgeprosser
Citizen
Posts: 68
Joined: Fri Mar 28, 2014 5:55 pm

Re: simple-slider

Post by georgeprosser »

qubodup wrote: What you should actually so that people can use this for LÖVE projects without hassle is put LÖVE's license.txt in your project, delete everything except lines 3-22 and replace the now-first line with the current year and your name. You can put a link or email address there as well if you like.
Thanks! I just updated the library with an MIT license.
User avatar
Kasperelo
Party member
Posts: 343
Joined: Fri Apr 13, 2012 1:47 pm
Location: The Milky Way

Re: simple-slider

Post by Kasperelo »

Looks really nice and simple! Love it!
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests