Game Development Community

how to create sprite animation ?

by gdyxml2000 · in Torque 3D Beginner · 05/20/2014 (7:35 am) · 7 replies

how to create sprite animation ?

#1
05/20/2014 (11:52 am)
Torque 3D doesn't have a sprite system. At best, you can have scrolling UVs on a material. Torque 2D has a full sprite system.
#2
07/06/2014 (12:54 am)
There is a resource for TGE 1.5.2 where the author added the function to use sprites for the player. There may be the need to update the code to work in the latest version of Torque 3D.

Here's the link.
#3
08/02/2014 (9:44 pm)
I have try a method ,effect like this:

data1.whicdn.com/images/130113325/large.pngdata1.whicdn.com/images/130113361/large.png



in particleEmitter.h

//*****************************************************************************
// Particle Emitter
//*****************************************************************************


//gdy customer sprite animation  add this line
class ParticleEmitterNode;




class ParticleEmitter : public GameBase
{
.....


/// @}

   bool mDead;



   //gdy customer sprite animation  add this line
   ParticleEmitterNode * parentEmitterNode;




  protected:
   /// @name Internal interface
   /// @{

in particleEmitter.cpp

#include "T3D/fx/particleEmitter.h"

//gdy customer sprite animation  add this line
#include "T3D/fx/particleEmitterNode.h"


//-----------------------------------------------------------------------------
// emitParticles
//-----------------------------------------------------------------------------
void ParticleEmitter::emitParticles(const Point3F& start,
                                    const Point3F& end,
                                    const Point3F& axis,
                                    const Point3F& velocity,
                                    const U32      numMilliseconds)
{
   if( mDead ) return;
   
   if( mDataBlock->particleDataBlocks.empty() )
      return;



   //gdy customer sprite animation  add this line
   //=================start========================
   if (mLifetimeMS > 0 && mElapsedTimeMS > mLifetimeMS)
   {
	   updateBBox();
	   if (n_parts > 0 && getSceneManager() == NULL)
	   {
		   gClientSceneGraph->addObjectToScene(this);
		   ClientProcessList::get()->addObject(this);
	   }
   }
   //=================end========================
   .....

//-----------------------------------------------------------------------------
// Update particles
//-----------------------------------------------------------------------------
void ParticleEmitter::update( U32 ms )
{
   // TODO: Prefetch

   for (Particle* part = part_list_head.next; part != NULL; part = part->next)
   {
      F32 t = F32(ms) / 1000.0;

      Point3F a = part->acc;
      a -= part->vel        * part->dataBlock->dragCoefficient;
      a -= mWindVelocity * part->dataBlock->windCoefficient;
      a += Point3F(0.0f, 0.0f, -9.81f) * part->dataBlock->gravityCoefficient;

      part->vel += a * t;
	  
      //part->pos += part->vel * t;//old

	  //gdy customer sprite animation  add this line
	  if (part->dataBlock->lifetimeVarianceMS < 0){
		  part->pos = parentEmitterNode->getPosition();
	  }
	  else{
		  part->pos += part->vel * t;
	  }
	 
  ....


#4
08/02/2014 (9:58 pm)
in the define .cs file:

datablock ParticleData(steam_puff){
 

   textureName = "art/datablocks/particle_gdy/imgs/aaa.png";
   dragCoefficient = 0.0;
   gravityCoefficient = 0.0;
   inheritedVelFactor = 0.0;
   lifetimeMS = "1";
   lifetimeVarianceMS = "-1";// this is more important
   windCoefficient = 0.0;
   useInvAlpha = 1;
   animateTexture = true;
   framesPerSec = 32;// speed of playing
   animTexTiling = "8 7";// column  row
   animTexFrames = "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49";
   colors[0] = "0.897638 0.897638 0.897638 1";
   colors[1] = "0.952756 0.0393701 0.173228 0.417323";
   colors[2] = "1 0 0.0866142 0.251969";
   sizes[0] = "15.16667";
   sizes[1] = "0";
   sizes[2] = "0";
   times[0] = 0.0;
   times[1] = "0.208333";
   times[2] = "0";
   spinSpeed = "0";
   animTexName = "art/datablocks/particle_gdy/imgs/aaa.png";
   sizes[3] = "0";
   times[3] = "0";


};



datablock ParticleEmitterData(steam_column){
        particles = steam_puff;
   ejectionPeriodMS = "1000";
   ejectionVelocity = "0";
   velocityVariance = "0";
   thetaMax = "138.8";
   phiVariance = "0";
   blendStyle = "NORMAL";
   alignParticles = "1";
   alignDirection = "0 0 1";
   thetaMin = "101.3";
   lifetimeMS = "1";
 
};


datablock ParticleEmitterNodeData(steam_source){
        timeMultiple = 1;
 
};



in the call .cs file :


%sprite = new ParticleEmitterNode(){
           //position = "32 -20 250";
           //rotation = "1 0 0 0";
           //scale = "1 1 1 1";
            dataBlock = steam_source;
            emitter = steam_column;
            velocity = 1;
        };

 %npc.mountObject(%sprite ,3);


this is sprite image:


data3.whicdn.com/images/130115234/large.png
#5
08/02/2014 (11:16 pm)
I was going to suggest customizing particles, but you beat me to it - this is the only place in T3D that uses this sort of animation as far as I know.
#6
08/03/2014 (8:12 am)
A simple primitive, or plane, with an animated material could give you something sprite-like.

If I remember correctly the image sheet is setup differently for them than the one shown above for particles...
#7
08/03/2014 (9:50 am)
Yeah, Michael - it's just a long horizontal strip. A little odd to work with.