TheConceptBoy Posted November 22, 2018 Share Posted November 22, 2018 Good day, everyone. I'm trying to get a hang of the animation function set and I'm trying to figure out how to use the endhooks in C++ From what I understand, it's a function that gets triggered once the animation has ended, however there are no example codes in the docs that actually show how that is written. Thank you. Quote Link to comment Share on other sites More sharing options...
catch22 Posted November 23, 2018 Share Posted November 23, 2018 Note the comments: Josh says that's only a lua function. Quote Coding for Christ. Link to comment Share on other sites More sharing options...
TheConceptBoy Posted November 23, 2018 Author Share Posted November 23, 2018 Ow Jesus. I was afraid of that.... Can we get something similar for firing up C++ functions perhaps? @Josh or that 0.0 - 1.0 animation solution starting to sound pretty suitable? Quote Link to comment Share on other sites More sharing options...
catch22 Posted November 23, 2018 Share Posted November 23, 2018 Well, I cannot speak for him of course, but that was 2 years ago and still nothing. It seems people just measure it themselves. I'll be doing this soon myself since animation is my next milestone...... Not a big fan of lua for core stuff like player controlling, so yeah. If I write something of use before you have a solution, i will gladly share it. 1 Quote Coding for Christ. Link to comment Share on other sites More sharing options...
Josh Posted November 23, 2018 Share Posted November 23, 2018 I believe if you use an Actor class, there is an EndAnimation function you can extend: https://www.leadwerks.com/learn?page=Tutorials_CPP_Actors virtual void EndAnimation(const int sequence); It's not in the docs because it is a sort of obscure thing I think was added in the last update. 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
catch22 Posted November 23, 2018 Share Posted November 23, 2018 I was bored. I wrote something in a few minutes. It's a mockup, I dunno? It works anyhow. I'm using EventEmitter I posted the other night in that other thread. https://gist.github.com/rioki/1290004d7505380f2b1d Or just ignore my ->on and ->emit stuff in the player class. It's just a callback function anyway. main loop: long currentTime; long dt; long lt; while (true) { if (window->Closed() || window->KeyDown(Leadwerks::Key::Escape)) return false; Leadwerks::Time::Update(); currentTime = Leadwerks::Time::GetCurrent(); dt = currentTime - lt; lt = currentTime; controller->update(dt); world->Update(); world->Render(); //dt = Leadwerks::Time::GetCurrent() - dt; context->SetBlendMode(Leadwerks::Blend::Alpha); context->SetColor(1.0, 1.0, 1.0); context->DrawStats(2, 2); context->Sync(false); } return 0; player class update function: // constructor .. this->on(EVENT_ANIMATION_END, function<void (const char*)>([this](const char* sequence) { std::cout << "Animation sequence '" << sequence << "' ended!" << std::endl; })); void update(long dt) { animationFrame += dt / ANIMATION_WALK_SPEED; if (animationFrame > model->GetAnimationLength("walk")) { animationFrame = 0; // this doesnt have to reset to 0 but rather whatever your state system dictates? this->emit(EVENT_ANIMATION_END, "walk"); } if (animationFrame < 0) { animationFrame = 0; } model->SetAnimationFrame(animationFrame, 0.8, "walk"); std::cout << "animationFrame: " << animationFrame << endl; }; EDIT: I guess it should be noted (at least in my model) it's 0 based animation sequences, so GetAnimationLength would return, for example 100 and your frames are 0-99; so offset appropriately. Also, I'm not blending or anything here (it's a hack come on!), so you'd take the remainder from the DT calculation and probably want to mix that into your wrap around to avoid hitching or smooth the interpolation =D Quote Coding for Christ. Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.