Author Topic: Enemy misbehaving (problem with sprite animations/movements)  (Read 2655 times)

0 Members and 1 Guest are viewing this topic.

The Pink Bunny

  • Newbie
  • *
  • Posts: 16
  • Zelda is your...
    • View Profile
Enemy misbehaving (problem with sprite animations/movements)
« on: February 21, 2017, 12:56:10 AM »
I'm trying to make a soldier enemy like ALttP, and I'm having some trouble getting it to walk right. The way I have it, the enemy does a "looking" animation (2 frames, 500ms frame delay, no loop), then begins a path movement and goes into a walking animation. But for some reason, after the "looking" animation ends, the sprite teleports a couple of tiles away and continues with the path movement. After looking at the console while it's happening, it appears that the path movement is happening during the 2 frame "looking" animation, but not displaying on either the game window or the console until the "looking" animation completes, then continuing with the path movement as if it had begun moving at the start of the "looking" animation. I don't know if this explanation is clear, but hopefully it's at least replicable.

I've tried writing it in every way I could think of, but they all either do what's described above, or do nothing after the "looking" animation as if I never told it to start the movement. Below is my current attempt (using a timer instead of defining a callback in sprite:set_animation() ), which does what is described in the first paragraph:

Code: ( lua) [Select]
-- move, sprite, paths, and the functions are declared above this in the full code

function pathset()

local dir = sprite:get_direction()



function look_around()

sol.timer.start(1000, pathset)


function soldier:on_restarted()



And here is another format of look_around() I've tried which does nothing at all on completing the animation:

Code: ( lua) [Select]
function look_around()

sprite:set_animation("looking", pathset)


I'm not sure what I could be doing wrong. Like I said, I've tried a bunch of different formats for this process, but I've deleted most of them out of frustration (probably a bad idea). The full enemies/soldier.lua is attached along with the sprite i'm using for it if anyone wants to try to replicate the error.