Implemented the ability for the user to add new input types#28
Open
snibo wants to merge 4 commits intotesselode:masterfrom
Open
Implemented the ability for the user to add new input types#28snibo wants to merge 4 commits intotesselode:masterfrom
snibo wants to merge 4 commits intotesselode:masterfrom
Conversation
Now you can have custom input types which means that any function that returns a number between 0 and 1 can be used as an input. Which is especially useful for touchscreen support.
Removed an unused piece of code
Added a "adding custom input types" section that explains how to use the "batton.newInputType()" function. It is still not very clear and still has some things that need explaining and is missing an example.
Fleshed out the "add custom input types" section with an example and explaining the parsing functions. Also mentioned that custom inputs types are not tracked as it's own input device
Owner
|
Can you show an example of how this would be used for UI? |
Author
|
Here is a working demo all you have to do is past it in main.lua with my branch of baton in the same file. What it does is using either the on screen buttons or the arrow keys (left/right) you can " browse through the pages". local baton = require('baton')
local page = 0
local x, y = love.mouse.getPosition()
local rightClick = love.mouse.isDown(1)
-- initializing the buttons
local buttonSize = 100
local buttons = {
back = {x = 0 , y = 200},
next = {x = buttonSize*2, y = 200},
}
-- input type constructor to detect button presses
baton.newInputType('ui', function(value)
local b = buttons[value]
local s = buttonSize
return (x > b.x and x < b.x+s and y > b.y and y < b.y+s and rightClick) and 1 or 0
end)
-- controls are set so you can browse through the pages with either
-- the ui or the arrow keys
local input = baton.new {
controls = {
back = {'key:left', 'ui:back'},
next = {'key:right', 'ui:next'},
}
}
function love.update(dt)
x, y = love.mouse.getPosition()
rightClick = love.mouse.isDown(1)
input:update()
if input:pressed('next') then
page = page + 1
elseif input:pressed('back') then
page = page - 1
end
end
-- rendering stuff don't pay attention
local function drawBox(x, y, w, h, r, g, b, name)
local lg = love.graphics
lg.setColor(r, g, b, 0.4)
lg.rectangle('fill', x, y, w, h)
lg.setColor(r, g, b, 1.0)
lg.rectangle('line', x, y, w, h)
lg.print(name, x + w/3, y + h/3)
lg.setColor(1,1,1,1)
end
function love.draw()
love.graphics.print('page: '..page, 0, 0)
for name, button in pairs (buttons) do
drawBox(button.x, button.y, buttonSize, buttonSize, 0, 0.5, 1, name)
end
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
As the title sais now you can make it so any function that can output a number between 0 and 1 to be it's own input type and can be used along side the other ones. For more details on how to use it check the bottom of the updated readme.md
This feature is useful for UI and especially for mobile games since it allows you to easily bind the touch controls using baton.