new example: interactivity
In the process I made a few bugfixes: * To improve the debug experience for myself I clear the canvas when recovering from any errors. (This should probably get ported upstream..) * The `car` handlers for each pane are now siloed from each other. When you navigate away they go away, when you navigate back they're still active. Very nice.
This commit is contained in:
parent
2227cadf24
commit
511aace3f1
|
@ -5,8 +5,10 @@ previous_pane_button = function()
|
|||
love.graphics.polygon('fill', Menu_left+5, App.screen.height/2, Menu_left+25, App.screen.height/2-10, Menu_left+25, App.screen.height/2+10)
|
||||
end,
|
||||
onpress1 = function()
|
||||
Current_pane.car = car
|
||||
Current_pane_index = Current_pane_index-1
|
||||
Current_pane = Panes[Current_pane_index]
|
||||
car = Current_pane.car or {}
|
||||
end,
|
||||
})
|
||||
end
|
|
@ -5,8 +5,10 @@ next_pane_button = function(r)
|
|||
love.graphics.polygon('fill', r-25, App.screen.height/2-10, r-25, App.screen.height/2+10, r-5, App.screen.height/2)
|
||||
end,
|
||||
onpress1 = function()
|
||||
Current_pane.car = car
|
||||
Current_pane_index = Current_pane_index+1
|
||||
Current_pane = Panes[Current_pane_index]
|
||||
car = Current_pane.car or {}
|
||||
end,
|
||||
})
|
||||
end
|
|
@ -40,10 +40,10 @@ Example_panes = {
|
|||
'end',
|
||||
},
|
||||
{
|
||||
'-- For animations and interactivity, you can define various functions that will get called for you.',
|
||||
'-- For animations, you can define various functions that will get called for you.',
|
||||
'-- LÖVE supports functions of the form love.*,',
|
||||
'-- for example, love.draw, love.update, love.keypressed, etc.',
|
||||
"-- You can't define those directly because Carousel Shell needs to define them, but you can define your own under car.*,",
|
||||
'-- for example, love.draw, love.update, etc.',
|
||||
"-- You can't define those directly because Carousel Shell needs to define them for its UI, but you can define your own under car.*,",
|
||||
'-- for example, car.draw, car.update, etc.',
|
||||
'Radius, dRadius = 100, 10',
|
||||
'function car.draw()',
|
||||
|
@ -56,6 +56,38 @@ Example_panes = {
|
|||
' if Radius < 30 then dRadius = -dRadius end',
|
||||
'end',
|
||||
},
|
||||
{
|
||||
'-- For interactivity, LÖVE provides functions like love.keypressed, love.mousepressed, etc.',
|
||||
'-- As before, define the corresponding car.keypressed, car.mousepressed, etc.',
|
||||
"-- A pane's interactive events only activate when the editor is hidden using the 'hide' button above.",
|
||||
"-- Try running this example and then pressing and holding the mouse and pressing and releasing keys.",
|
||||
'-- Then try hiding the editor and again pressing and holding the mouse and pressing and releasing keys',
|
||||
'X, Y, dX = 100, 0, 10',
|
||||
"Log = ''",
|
||||
'',
|
||||
'function car.draw()',
|
||||
' love.graphics.line(X,Y, X,Y+300)',
|
||||
' love.graphics.print(Log, 50,50)',
|
||||
'end',
|
||||
'',
|
||||
'function car.update(dt)',
|
||||
' if X > 500 then dX = -dX end',
|
||||
' if X < 100 then dX = -dX end',
|
||||
' X = X+dX',
|
||||
'end',
|
||||
'',
|
||||
'function car.mousepressed(x,y, button)',
|
||||
' Y = y',
|
||||
'end',
|
||||
'',
|
||||
'function car.mousereleased(x,y, button)',
|
||||
' Y = 0',
|
||||
'end',
|
||||
'',
|
||||
'function car.keypressed(key)',
|
||||
' Log = Log..key',
|
||||
'end',
|
||||
},
|
||||
{
|
||||
'-- Some abbreviations to reduce typing.',
|
||||
'g = love.graphics',
|
||||
|
|
1
live.lua
1
live.lua
|
@ -382,6 +382,7 @@ end
|
|||
|
||||
-- return nil to continue the event loop, non-nil to quit
|
||||
function live.handle_error(err)
|
||||
love.graphics.setCanvas() -- undo any canvas we happened to be within, otherwise LÖVE seizes up
|
||||
Mode = 'error'
|
||||
local callstack = debug.traceback('', --[[stack frame]]2)
|
||||
local cleaned_up_error = 'Error: ' .. cleaned_up_frame(tostring(err))..'\n'..cleaned_up_callstack(callstack)
|
||||
|
|
Loading…
Reference in New Issue