I have created a GUI node - box and added texture “frog.atlas”. Even able to run animation via editor. Now, I am trying to run “frog” animation when a player tapped on node.
In the .gui_script, I received “touch” gesture and its node as well.
function on_input(self, action_id, action)
if action_id == hash("touch") and action.pressed then
local frog = gui.get_node("frog")
if gui.pick_node(frog, action.x, action.y) then
print("Frog clicked - do animation. ")
--Do Frog animation
end
end
end
function on_input(self, action_id, action)
if action_id == hash("touch") and action.pressed then
local frog = gui.get_node("frog")
if gui.pick_node(frog, action.x, action.y) then
print("Frog clicked - do animation. ")
-- do Frog animation
gui.set_texture(frog, "frog") -- atlas
gui.play_flipbook(frog, "your-animation-id") -- image
end
end
end
Opened a blank project and removed the logo, background and main.script file
Removed the logo and background images from the main.atlas and added two new images to an animation group called flash
Created main.gui and main.gui_script
Attached the main.gui_script file to the main.gui component
Added the main.gui component to the blueprint game object in the main.collection
Created a box node in main.gui, added a system font and added a texture (main.atlas)
Added input focus on the GUI (main.gui_script)
function init(self)
msg.post(".", "acquire_input_focus")
end
Placed the code I sent earlier and adjusted it to this project (main.gui_script)
function on_input(self, action_id, action)
if action_id == hash("touch") and action.pressed then
local boxnode = gui.get_node("box")
if gui.pick_node(boxnode, action.x, action.y) then
print("box has been touched. ")
-- start the animation
gui.set_texture(boxnode, "main") -- set the texture on the gui which is an atlas
gui.play_flipbook(boxnode, "flash") -- set the animation group or image
end
end
end
@amel It worked … !! I was almost gave up until now. Thank you so much.
Mistake : Playback was set ‘None’ instead of ‘Once Forward’. and also was not sure of flipbook name in the gui_script.