Hi everyone. Sorry for my bad english=)
I am new in Defold and lua, so my game will be very simple, because i want to understand all concepts of engine and lua.
I am making a simple arcade. Where you shoot asteroids. The main idea
1)player shoot asteroids and get scores
2)the more time you play, the faster appearing new asteroids
Nice! Congratulations on creating a game using Defold. I took a very quick look at the code and nothing sticks out, it looks organised and well written. One minor thing though, if you don’t use the update() function (or any of the other lifecycle functions) it is recommended to remove them since they will be called and you will waste precious CPU cycles.
Why defold have not got ui elements:buttons, checkboxes, sliders etc.
It is easy to create them, but i think this elements must be in engine.
I use checkbox to enbale/disable sounds.
function M.getCheckBox(checked,imageOn,imageOff,node)
local checkBox = {imageOn=imageOn, imageOff=imageOff,checked=true,node=node}
checkBox.setChecked =
function(checked)
checkBox.checked=checked
local animation=checkBox.imageOn
if(not checked)then animation=checkBox.imageOff end
gui.play_flipbook(node,animation)
if(not (checkBox.callback == nil))then
checkBox.callback(checkBox.checked)
end
return checkBox
end
checkBox.clicked =
function(action)
if(gui.pick_node(node, action.x, action.y) and action.pressed)then
checkBox.setChecked(not checkBox.checked)
return true
else
return false
end
end
checkBox.setChecked(checked)
return checkBox
end
function M.get_button(up,down,node)
local button = {up=up, down=down,over=nil,node=node}
button.clicked =
function(action)
if(gui.pick_node(node, action.x,action.y)) then
if(action.released)then
print("clicked")
gui.play_flipbook(node,up)
return true
elseif(action.pressed or not(action.repeated == nil)) then
gui.play_flipbook(node,down)
return false
end
else
gui.play_flipbook(node,up)
return false
end
end
return button
end
People will always want some custom behavior. So these kinds of things are better suited for a library. Either community contributed or official. If you make some good UI controls share and others may too.