Hey there.
I am at a gui animation for my buttons.
Cant find the problem why it works with some GUI and dont work with other GUIs.
The buttons should pop-up (increase size) with the ping-pong-once effect. Most of the buttons work fine, but others seems to “stock” -meaning, the button dont get bigger and smaller again, it gets just a bit bigger and stops! On a mouse-move it gets a little big bitter and stops again until the max. size is reached.
To prevent calling the animate_button() every pixel-movement with the mouse I am trying to handle this with a lua-table.
That table stores a key-value which simply is the node-Id and TRUE if its already animating or NIL if not (or never).
Strange is, the lua table stores tons of same keys. I’ve tried that script in a lua-editor. Normally it shouldnt do that. One key per table like table[1] = 1. If table[1] = 2 then its 2 - not even have 2 entries. But if I printout the table there are tons of same entries.
Here are some code to look at:
the functions for animating:
function on_animation(self, node)
if self.animatedbuttons[node] then
print("MAINMENU: animation stopped: " .. tostring(node))
self.animatedbuttons[node] = nil
pprint(self.animatedbuttons)
end
end
function animate_button(self, node)
if self.animatedbuttons[node] == nil then
gui.animate(node, gui.PROP_SCALE, vmath.vector3(1.1, 1.1, 1.1), gui.EASING_LINEAR, 0.3, 0.1, on_animation, gui.PLAYBACK_ONCE_PINGPONG)
print("MAINMENU: animation started: " .. tostring(node))
self.animatedbuttons[node] = true
end
end
And in different GUI.scripts calls like animate_button(self, nodeID).
Here is the simple and easy mainmenu-gui-script where the animations stucks:
function init(self)
msg.post(".","acquire_input_focus")
gui.set_text(gui.get_node("game-logo/logo"), sys.get_config("project.title"))
gui.set_text(gui.get_node("game-logo/versiontext"), sys.get_config("project.version"))
gui.set_text(gui.get_node("defoldtext"), sys.get_engine_info().version)
self.animatedbuttons = {}
end
function on_input(self, action_id, action)
if GLOBAL.GAMESTATE <= GLOBAL.GAMESTATE_PAUSE then
local start = gui.get_node("button_start")
local options = gui.get_node("button_options")
local quit = gui.get_node("button_quit")
local clicked = action_id == GLOBAL.LEFTCLICKED and action.released
if gui.pick_node(start, action.x, action.y) then -- CLICK ON START
animate_button(self, start)
if clicked then
GLOBAL.GAMESTATE = GLOBAL.GAMESTATE_PLAY
msg.post(".", "disable")
msg.post("main:/gamecam", "enable")
print("GAME STARTED")
end
elseif gui.pick_node(options, action.x, action.y) then -- CLICK ON OPTIONS
animate_button(self,options)
elseif gui.pick_node(quit, action.x, action.y) then -- CLICK ON QUIT
animate_button(self,quit)
if clicked then
print("GAME QUIT)")
msg.post("@system:", "exit", {code = 0})
end
end
end
end
Otherwise here is a much more complicated gui-script where the button-animation DONT WORK for the first simple calls (move, engage up to suicide) BUT … at the end at the FOR-LOOP, where the dynamiclly genereated buttons are, IT WORKS PERFEKT.
function on_input(self, action_id, action)
local clicked = action_id == GLOBAL.LEFTCLICKED and action.released
print("UNITGUI: CLICK")
-- UNITMENU like MOVE, ENGAGE, SUICIDE OR BUILD
local move = gui.get_node("unitmenu/movebutton")
local fire = gui.get_node("unitmenu/firebutton")
local build = gui.get_node("unitmenu/buildbutton")
local suicide = gui.get_node("unitmenu/suicidebutton")
-- CLICK on MOVE
if gui.pick_node(move, action.x, action.y) then
animate_button(self,move)
if clicked then
unitMenu(false)
buildMenu_Structures(false)
msg.post("main:/crosshair#script", "moveunit")
return true
end
-- CLICK on ENGAGE/FIRE
elseif gui.pick_node(fire, action.x, action.y) then
animate_button(self,fire)
if clicked then
unitMenu(false)
buildMenu_Structures(false)
msg.post("main:/crosshair#script", "engageunit")
return true
end
-- CLICK on BUILD
elseif gui.pick_node(build, action.x, action.y) then
animate_button(self,build)
if clicked then
msg.post("main:/crosshair#script", "buildMenu_Structures")
buildMenu_Structures(true, gui.get_position(build))
return true
end
-- CLICK on SUICIDE
elseif gui.pick_node(suicide, action.x, action.y) then
animate_button(self,suicide)
if clicked then
unitMenu(false)
buildMenu_Structures(false)
msg.post("main:/crosshair#script", "suicideunit")
return true
end
else
-- CLICK on the BUILD-MENU
for v, i in ipairs(buildStructureMenuItems) do
if gui.pick_node(buildStructureMenuItems[v][hash("buildmenu/button_buildstructure_base")], action.x, action.y) then
animate_button(self, buildStructureMenuItems[v][hash("buildmenu/button_buildstructure_base")])
if clicked then
unitMenu(false)
print("CLICK ON " .. buildStructureMenuItems[v]["sprite"])
-- TODO: disable new dyn menu
msg.post("main:/crosshair#script", "buildStructure", { structure = buildStructureMenuItems[v]["sprite"] , factory_url = buildStructureMenuItems[v]["spawner"] })
return true
end
end
end
end
end
Any ideas why?
And … any ideas why lua stores tons of same keys?
Here is a sample-debug print:
DEBUG:SCRIPT: MAINMENU: animation started: box@(640, 350, 0)
DEBUG:SCRIPT: MAINMENU: animation started: box@(640, 350, 0)
DEBUG:SCRIPT: MAINMENU: animation started: box@(640, 350, 0)
DEBUG:SCRIPT: MAINMENU: animation started: box@(640, 350, 0)
DEBUG:SCRIPT: MAINMENU: animation started: box@(640, 350, 0)
DEBUG:SCRIPT: MAINMENU: animation started: box@(640, 350, 0)
DEBUG:SCRIPT: MAINMENU: animation started: box@(640, 350, 0)
DEBUG:SCRIPT: MAINMENU: animation started: box@(640, 350, 0)
DEBUG:SCRIPT: MAINMENU: animation started: box@(640, 350, 0)
DEBUG:SCRIPT: MAINMENU: animation started: box@(640, 350, 0)
DEBUG:SCRIPT: MAINMENU: animation started: box@(640, 350, 0)
DEBUG:SCRIPT: MAINMENU: animation started: box@(640, 350, 0)
DEBUG:SCRIPT: MAINMENU: animation started: box@(640, 350, 0)
DEBUG:SCRIPT: MAINMENU: animation started: box@(640, 350, 0)
DEBUG:SCRIPT: MAINMENU: animation stopped: box@(640, 350, 0)
DEBUG:SCRIPT:
{
box@(640, 350, 0) = true,
box@(640, 350, 0) = true,
box@(640, 350, 0) = true,
box@(640, 350, 0) = true,
box@(640, 350, 0) = true,
box@(640, 350, 0) = true,
box@(640, 350, 0) = true,
box@(640, 350, 0) = true,
box@(640, 350, 0) = true,
box@(640, 350, 0) = true,
box@(640, 350, 0) = true,
box@(640, 350, 0) = true,
box@(640, 350, 0) = true,
}
//EDIT
I’ve made a quick video to show. At the beginning I’ll move the mouse over the 3 main-menu buttons. If I move faster over all 3 buttons they dont animate anymore. They “stuck”. Later you’ll see a longer list of buttons working fine. The other 3 buttons at the units have the same problem like the main-menu.