Greeting friends, it’s question time again…
I’m trying to stun my main character briefly when he gets hit by a “danger” object. This is my best effort so far:
I have two problems that I’m struggling to figure out. 1. My stun animation is not playing all the way through. 2. I haven’t found an effective way to temporarily disable and then re-enable input.
Here’s the relevant part of my update function:
function update(self, dt)
local p = go.get_position()
if self.got_hit then
self.counter = self.counter + dt
msg.post("#collisionobject", "disable")
if self.facing == "r" then
msg.post("#sprite","play_animation", {id = hash("animstunright")})
else
msg.post("#sprite","play_animation", {id = hash("animstunleft")})
end
p = p -- freeze
if self.counter >= self.stun_time then
self.got_hit = false
self.counter = 0
msg.post("#collisionobject", "enable")
if self.facing == "r" then
msg.post("#sprite","play_animation", {id = hash("animright")})
else
msg.post("#sprite","play_animation", {id = hash("animleft")})
end
end
go.set_position(p)
else...
-
The Animation issue…
Sorry guys just figured this one out, moved the play_animation out of update() -
The input issue…
I want input for the player to stop completely during self.stun_time. At first I tried putting ‘msg.post(".", “release_input_focus”)’ right after ‘if self.got_hit’ and then ‘msg.post(".", “acquire_input_focus”)’ inside ‘if self.counter >= self.stun_time’ to get input going again. This first part worked. All movement stopped, but some really funky things happened with the player movement, when he’d come out of being stunned if you pressed any of the usual control buttons while he was stunned. He’d fly in a random direction and you couldn’t get back control for a bit. I set up a print test to the console and these weird movements definitely happened after coming out of the stun time. It’s strange to me that input focus isn’t restored straight away. Is there some other way around this? I scrapped that and moved on to the code as is above. Problem is the player is still able to wiggle left and right. I tried to stop that. In on_input, I added the qualifier, “and not self.got_hit”, to the if action_id == hash(“left”) and right segments of my code, but this created the same weird movements if you fiddled with the buttons while stunned. Send help please.