Jump to content
  • entries
    944
  • comments
    5,899
  • views
    929,624

New Animation Commands


Josh

5,007 views

 Share

I've built a modified version of ReepBlue's C++ animation manager class (based off my Lua script) into the engine. This adds a new command and eliminates the need for the animation manager script.

 

void Entity::PlayAnimation(const std::string& sequence, const float speed=1.0f, const int blendtime=500, const int mode=0, const std::string endhook="")

void Entity::PlayAnimation(const int index, const float speed = 1.0f, const int blendtime = 500, const int mode = 0, const std::string endhook = "")

 

The animation manager only updates when the entity is drawn, so this does away with the most common use of the entity draw hook. This will make the engine a bit simpler to use, and existing code will still work as before.

Usage in Lua

Although the animation manager script has been removed from the default scripts, you do not need to modify your existing projects.

 

The AI, weapon, and animation scripts have been updated to use the built-in animation manager. Previously these scripts would create an AnimationManager lua table and call it like this:

self.animationmanager:SetAnimationSequence("Idle",0.02)

 

These calls now look like this:

self.entity:PlayAnimation("Idle",0.02)

 

One-shot animations that call a callback when the end of the sequence is reached used to look like this:

self.animationmanager:SetAnimationSequence("Death",0.04,300,1,self,self.EndDeath) 

 

Now we just pass the function name in:

self.entity:PlayAnimation("Death",0.04,300,1,"EndDeath"

 

Again, as long as you have the old AnimationManager.lua script in your project, your existing scripts do not need to be updated.

 

Animation callbacks are not yet supported in C++.

 

This update will be available later today, for C++ and Lua, on all platforms.

  • Upvote 8
 Share

9 Comments


Recommended Comments

I prefer the Lua version since I can modify it to allow a callback on a "special" frame that I set or on every frame if I want to allow me to do certain things. Usually for an attack animation on the frame that would hit the target playing particles and doing damage to perhaps rainbow out in text. I've done playing footstep sounds when the feet would hit the floor. This sort of limits that. I'll just pull that script and continue using it but this version is more limiting in that respect.

 

Is EndDeath a global function in Lua or a script function like we had it with the old animation manager?

 

So you're taking away the entity draw callback? That kind of screws over using the old animation manager for its flexibility then right?

Link to comment

EndDeath, in the example above, would be an entity script function, just like before. The object itself does not have to be passed to the function since the entity already is associated with the Lua table.

Link to comment
The animation manager only updates when the entity is drawn, so this does away with the most common use of the entity draw hook.

 

Can you keep the draw hook please? If not then letting us define any number of callbacks at any point in the animation would be ideal. You could just make a function named AddAnimationCallback(callbackName, frame). Then if we set -1 to the frame param it means the end of the animation, otherwise it means the actual frame of the animation to call.

  • Upvote 1
Link to comment

Once something is in the API and released, it doesn't go away. Of course the existing method will remain.

 

In a future engine the renderer might be running on a separate thread, and a draw hook could become impractical in that kind of design. But that would be a new engine, not the existing one.

Link to comment

Yeah, you shouldn't need to call another script, or code a whole class just to do basic animations. When I was new to Leadwerks, I didn't understand why the default SetAnimation command didn't just work. But I understand cases where you might want the older system yourself though.

 

I'm glad I was able to contribute to the engine. I was actually gonna expose this myself, but I was still getting bugs with my code with looping animations. (Although I was the only one getting them!). Didn't see any issues with the existing code though!

 

 

In a future engine the renderer might be running on a separate thread, and a draw hook could become impractical in that kind of design. But that would be a new engine, not the existing one.

 

New engine? Or you mean when you revamp the engine for Vulkan?

Link to comment
New engine? Or you mean when you revamp the engine for Vulkan?

Well, I'm never going to write a new engine from scratch but Vulkan support or a major architecture change would be a new engine basically.

Link to comment

Since this has not been put on the release branch yet, I am renaming the command "SetAnimation" to "PlayAnimation".

Link to comment
Guest
Add a comment...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...