Below is a copy of my character script. I removed the animation portion of the “toggle_right” in attempts to see if I could simply get it to move across the screen on the x axis, but no luck.
--local currentAnimation = 0
function init(self)
self.speed = vmath.vector3()
msg.post(".", "acquire_input_focus")
end
function update(self, dt)
local pos = go.get_position()
pos = pos + (self.speed * dt)
go.set_position(pos)
end
function on_message(self, message_id, message, sender)
-- Add message-handling code here
-- Remove this function if not needed
end
function on_input(self, action_id, action)
-- Input Right
if action_id == hash("toggle_right")then
--msg.post("#sprite", "play_animation", { id = hash("malewalkRight") })
--self.currentAnimation = 0
self.speed.x = (action.pressed and 1) or (action.released and 0) or self.speed.x
--Input Left
else if action_id == hash("toggle_left") and action.pressed == true then
if self.currentAnimation == 1 then
msg.post("#sprite", "play_animation", { id = hash("malewalkLeft") })
self.currentAnimation = 0
else
msg.post("#sprite", "play_animation", { id = hash("maleidleLeft") })
self.currentAnimation = 1
end
--Input Up
else if action_id == hash("toggle_up") and action.pressed == true then
if self.currentAnimation == 1 then
msg.post("#sprite", "play_animation", { id = hash("malewalkUp") })
self.currentAnimation = 0
else
msg.post("#sprite", "play_animation", { id = hash("maleidleUp") })
self.currentAnimation = 1
end
--Input Down
else if action_id == hash("toggle_down") and action.pressed == true then
if self.currentAnimation == 1 then
msg.post("#sprite", "play_animation", { id = hash("malewalkDown") })
self.currentAnimation = 0
else
msg.post("#sprite", "play_animation", { id = hash("maleidleDown") })
self.currentAnimation = 1
end
end
end
end
end
end