Per frame animation data
by Lennart Steinke · in Torque Game Builder · 03/23/2005 (7:16 am) · 6 replies
I was talking with a friend about t2d, and since he wants to code a beat-em-up, we were talking about the option he has when he needs to track certain points per frame and if he can have different collision polygons for each frame.
Right now, I'd say this can't be done directly, so he'd have to code this himself, but it shouldn't be too hard. He'd need to store a string for each frame for each collision rect and set it on frame change.
Then I checked the animatedSprite class and realized that there is no callback on frame change - so how would one do that ideally?
This is pretty strange for me... I could code something like this in C pretty easily, but I'm not sure how I'd to this with t2d and TGEScript.
So, what should I tell him?
-Lenny
Right now, I'd say this can't be done directly, so he'd have to code this himself, but it shouldn't be too hard. He'd need to store a string for each frame for each collision rect and set it on frame change.
Then I checked the animatedSprite class and realized that there is no callback on frame change - so how would one do that ideally?
This is pretty strange for me... I could code something like this in C pretty easily, but I'm not sure how I'd to this with t2d and TGEScript.
So, what should I tell him?
-Lenny
About the author
#2
I think the only way to be exact about the frame-change is to implement a minor piece of code in...
You could then call something like...
So you don't have to wait for the update, here are the definitions of those new functions for fxAnimatedSprite2D...
The above is on the fly a little so I might've missed something but it's pretty easy to add stuff like this when you've done it a few times. :)
All in all, a few lines of code should get you up and running.
We'll be seriously looking at per-frame collision polygons at a later date as well as other stock collision primitives like swept circles and much more.
- Melv.
03/23/2005 (7:34 am)
It's an interesting idea to have a per-frame callback but it could get expensive fast with lots of items.I think the only way to be exact about the frame-change is to implement a minor piece of code in...
void fxAnimatedSprite2D::integrateObject( F32 sceneTime, F32 elapsedTime, CDebugStats* pDebugStats )The call..
mAnimationController.updateAnimation( elapsedTime );...updates the animation and you can call...
mAnimationController.getCurrentFrame()... to get the current frame (or at least you will in the update because this is a new recent function). Using this, you can obviously create a "mLastFrame" class member that you can use to compare so that you know if a frame has changed. You'd just need to reset it when "playAnimation()" is called.
You could then call something like...
Con::executef( this, 1, "onFrameChange" );... and in the callback, call (new function in the next update) "getAnimationFrame()" on the fxAnimatedSprite2D like...
function fxAnimatedSprite2D::onFrameChange(%this)
{
%newFrame = %this.getAnimationFrame();
}So you don't have to wait for the update, here are the definitions of those new functions for fxAnimatedSprite2D...
//-----------------------------------------------------------------------------
// Is Animation Finished?
//-----------------------------------------------------------------------------
ConsoleMethod(fxAnimatedSprite2D, getIsAnimationFinished, bool, 2, 2, "Checks animation status.")
{
// Return Animation Finished Status.
return object->mAnimationController.isAnimationFinished();
}
//-----------------------------------------------------------------------------
// Get Animation Name.
//-----------------------------------------------------------------------------
ConsoleMethod(fxAnimatedSprite2D, getAnimationName, const char*, 2, 2, "Gets current animation name.")
{
// Get Current Animation.
return object->mAnimationController.getCurrentAnimation();
}
//-----------------------------------------------------------------------------
// Get Animation Frame.
//-----------------------------------------------------------------------------
ConsoleMethod(fxAnimatedSprite2D, getAnimationFrame, S32, 2, 2, "Gets current animation frame.")
{
// Get Animation Frame.
return object->mAnimationController.getCurrentFrame();
}... and fxAnimationController2D header...const U32 getCurrentFrame(void) { return mCurrentFrameIndex; };The above is on the fly a little so I might've missed something but it's pretty easy to add stuff like this when you've done it a few times. :)
All in all, a few lines of code should get you up and running.
We'll be seriously looking at per-frame collision polygons at a later date as well as other stock collision primitives like swept circles and much more.
- Melv.
#3
I was expecting some general ideas, and what do I get? Solutions!
This is just great.
Hm... well, if it's always that easy... let's try:
I was wondering if there is a chance that T2D will cook my coffee, so I can continue coding all night. I think this would be beneficial for almost all coders...
Let's see if this works (/me crosses fingers)
-Lenny
03/23/2005 (9:40 am)
Wow! Thanks for those great replies :)I was expecting some general ideas, and what do I get? Solutions!
This is just great.
Hm... well, if it's always that easy... let's try:
I was wondering if there is a chance that T2D will cook my coffee, so I can continue coding all night. I think this would be beneficial for almost all coders...
Let's see if this works (/me crosses fingers)
-Lenny
#4
Now that i think about it, i kinda want that now...
edit: upon searching, this RFC might be of some use to you:
www.faqs.org/rfcs/rfc2324.html
03/23/2005 (10:06 am)
Hm, you could use some x10 home automation equipment with your standard coffee pot, and then maybe write an interface to the controller, and a program that monitors launching of the t2d binary. every 15 launches, brew a new pot. Heh.Now that i think about it, i kinda want that now...
edit: upon searching, this RFC might be of some use to you:
www.faqs.org/rfcs/rfc2324.html
#5
- Melv.
03/23/2005 (11:46 am)
Unfortunately, no matter how hard I tried, the "fxCoffeeBrewsky" didn't make it into the EA build. Just kept spilling stuff everywhere and generally messed-up. Maybe in the final release. ;)- Melv.
#6
holy cow im a geek. And i like it :)
fxCoffeeBrewsky sounds like a delicious alcohol fuled coffee (or coffee flavored beer... yuck)
03/23/2005 (2:21 pm)
See, the problem is you need to dampen the hand.shakes in order to keep steady. You'll have that if you schedule the fxCoffeeBrewsky object to be created too frequently.holy cow im a geek. And i like it :)
fxCoffeeBrewsky sounds like a delicious alcohol fuled coffee (or coffee flavored beer... yuck)
Torque 3D Owner Matthew Langley
Torque
then again these are completely off the top of my head