I am trying to animate a factory on a platformer. So far i have done the following:
-
I have created a folder named “enemies”. I have added three files inside:
1)Atlas
2)Game object
3) Script for the game object
-
Inside the atlas, i have created an animation group and added my animation.
-
Inside the game object, i have added a reference to the script and added a sprite that refers to the animation i created previously in the atlas.
-
In the script, i have added the following simple logic in the enemies script, inside the update function:
self.targetPosition = go.get_position("player") local enemyPosition = go.get_position() if enemyPosition.x < self.targetPosition.x then self.velocity.x = 50 sprite.set_hflip(go.get_id(), true) msg.post(go.get_id(), "play_animation", {id = hash("level1enemy1")}) else self.velocity.x = - 50 sprite.set_hflip(go.get_id(), false) msg.post(go.get_id(), "play_animation", {id = hash("level1enemy1")}) end go.set_position(go.get_position() + self.velocity * dt)
The result is as follow:
Then i have tried to animate it. I added the following line to the enemies script, in the init function, but no animation happens, and it the object keeps going in one direction, disappears and then reappear again. Here is how i animated it:
go.animate(go.get_id(), "position.x", go.PLAYBACK_LOOP_FORWARD, 20, go.EASING_LINEAR, 1.5)
What i want to achieve is this:
If you can see, each time the object animates, there is jump. The jump is there in the animation. What i want is to animate it in the same behavior such that it does’t move, it only jumps when the animation triggers.