Game Development Community

Frame by frame animation

by Peter Verschuere · in Torque Game Builder · 07/17/2005 (1:22 pm) · 11 replies

I am a starter with T2D, coming from a Flash background. I went trough the basic tutorial pdf that comes with the engine, and did some other reading (forums, docs etc).
Anyway, I wanted to get started with a simple test project, and ran into a little problem:
For my player sprite I want to use a series of images (20 in total). I want to display a certain frame based on some parameters. In Flash I would make an onEnterFrame function, and do the checks in there, then set the movieclip to the frame I want to to be at. But how do I do this in T2D, what's the right way? I think I need to add a schedule so i can check regulary (or is there a function that gets called regulary? like the flash onEnterFrame...), what else do I need? How can I make a sprite that has multiple frames, and I can tell it wich frame to show? Or isn't there an easy way in T2D to do this?
Thanks in advance, and sorry if this info can be found in the documentation.

#1
07/17/2005 (7:54 pm)
Read this to learn about setting up the animation. If you want to define what frame you'd like the animation set to (and not play) then you'll have to use a static sprite. Animated sprites can't be set to a certain frame and held there. Well, not out of the box anyways.
#2
07/19/2005 (4:23 pm)
Hmm.... but maybe i can make an animation datablock on the fly. Looks like a workaround tough. Too bad I can't just tell it wich frame it should display.
#3
07/20/2005 (11:37 am)
Something like this (passing it the proper imagemap) should generate animation datablocks for each frame of an imagemap


function createFrameAnims(%imagemap)
{
   %count = %imagemap.getImageMapFrameCount();

   for(%i=0;%i<%count;%++)
   {
      datablock fxAnimationDatablock2D(%imagemap @ "frame" @ %i)
      {
         imageMap = %imagemap;
         animationFrames = %i;
         animationTime = 1;
         animationCycle = 0;
         randomStart = 0;
      };
   }
}

they will be named the name of the image map plus "frame" then the frame number...

so testImageMap

frame 2 animation will be

.playAnimation(testImageMapframe2);

I don't have time to test this yet though
#4
07/21/2005 (1:34 pm)
Thanks, I'll try this. Like i said, this looks a bit like a work-around, but that's ok for now.
#5
07/21/2005 (2:52 pm)
Doesn't seem to work. Are you sure you can create datablocks on the fly like this? Doesn't seem to accept a variable for the datablock name.
#6
07/21/2005 (2:55 pm)
Maybe I should also tell you what I need this for... becuase maybe there's another way of doing this:

I have a set of 10 frames. Its an animation of a ship rolling from -45 degrees to 45 degrees. Now, based on the Y-movement of the ship, i want to set it to a certain frame. This way, the ship will roll when it moves. The way I see it, I'll have to put a shedule on my player object that checks minimum 24 times per second wich frame it should show, and show that frame.
#7
07/21/2005 (3:33 pm)
I understand what you're wanting to do and it sounds like a fine idea. However, the TScript interface to T2D is based on events, not frame-by-frame analysis. And since (I don't think, anyway) there is no "on_tick" event (note to Melv: make an "on_tick" event if you haven't done so already), the only recourse you have is to use some kind of timer or build it into the actual code.
#8
07/22/2005 (9:22 am)
Well, I can easely make my own "on_tick" by setting up a function that is scheduled like 24 times per second... but that doesn't solve me frame problem. Right now I can create 10 datablocks by hand, but what if I want to do the same with a 50 frame animation? Oh well, I'll just stick to 10-20 frame animations to keep it simple ;)

*edit * Would be nice to have an on_tick tough ;) */edit*
#9
07/22/2005 (11:37 am)
Actually, I believe there is a tick function that gets called every frame. It's called "fxSceneObject::onSceneUpdate". I saw it on another thread.
#10
07/22/2005 (11:45 am)
Smaug is correct :)

though it should be

fxSceneGraph2D::onUpdateScene()
#11
07/22/2005 (11:50 am)
Also in the early version of TGE 1.4 (if you have license to that you can grab it off of CVS) there is a GuiTickCtrl... The TGE 1.4 core updates that TGE already shares with T2D (like Gui stuff) will make its way into T2D.