I’m trying to make a really simple project called “SODA Designer”, where you can use Codea’s interactive parameters to play with the size and shape and color and etc of a SODA Button, and see the results in real time.
I started by trying make an adjustable width.
Seemed simple: I made a button called “guineaPig”, a parameter called “ButtonWidth”, and a callback function that sets the “w” variable of guineaPig to the current value of ButtonWith.
Doesn’t work. I can’t figure out why. I’ve tried a bunch of different things but none helped.
(For anyone interested: the project needs SODA as a dependency before it will actually run).
--SODA Designer
function setup()
displayMode(OVERLAY)
--SODA:
profiler.init()
Soda.setup()
--/SODA
guineaPig = Soda.Button{
title = "OK",
x = 0.5, y = 0.5, w = 0.4, h = 40,
}
parameter.number("ButtonWidth", 0, 1, 0.25, changeWidth)
end
function changeWidth()
if guineaPig ~= nil then
guineaPig.w = ButtonWidth
end
end
function draw()
--SODA
pushMatrix()
Soda.camera()
drawing()
popMatrix()
profiler.draw()
--/SODA
end
function drawing(breakPoint)
pushStyle()
spriteMode(CORNER)
sprite("Cargo Bot:Game Area", 0, 0, WIDTH, HEIGHT)
popStyle()
--SODA
--in order for gaussian blur to work, do all your drawing here
Soda.draw(breakPoint)
--/SODA
end
function touched(touch)
--SODA
if Soda.touched(touch) then return end
--/SODA
end
--MISC SODA STUFF
--user inputs:
function keyboard(key)
Soda.keyboard(key)
end
function orientationChanged(ori)
Soda.orientationChanged(ori)
end
--measure performance:
profiler={}
function profiler.init(quiet)
profiler.del=0
profiler.c=0
profiler.fps=0
profiler.mem=0
if not quiet then
parameter.watch("profiler.fps")
parameter.watch("profiler.mem")
end
end
function profiler.draw()
profiler.del = profiler.del + DeltaTime
profiler.c = profiler.c + 1
if profiler.c==10 then
profiler.fps=profiler.c/profiler.del
profiler.del=0
profiler.c=0
profiler.mem=collectgarbage("count", 2)
end
end