Page 1 of 3

simple-slider

Posted: Wed Aug 12, 2015 2:07 pm
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 660 times
demo.love
(1.88 MiB) Downloaded 419 times

Re: simple-slider

Posted: Wed Aug 12, 2015 3:53 pm
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:

Re: simple-slider

Posted: Wed Aug 12, 2015 7:08 pm
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.

Re: simple-slider

Posted: Wed Aug 12, 2015 7:17 pm
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).

Re: simple-slider

Posted: Wed Aug 12, 2015 9:50 pm
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?

Re: simple-slider

Posted: Wed Aug 12, 2015 11:15 pm
by qubodup
Very nice demo, fun to play around with! :crazy:

http://youtu.be/hlWzLV1yMH4

Re: simple-slider

Posted: Thu Aug 13, 2015 8:01 pm
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.

Re: simple-slider

Posted: Thu Aug 13, 2015 9:21 pm
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.

Re: simple-slider

Posted: Thu Aug 13, 2015 9:38 pm
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.

Re: simple-slider

Posted: Thu Aug 13, 2015 10:46 pm
by Kasperelo
Looks really nice and simple! Love it!