Game Development Community

Engine freezes while calling particle effect...

by Isaac Barbosa · in Torque Game Builder · 08/21/2007 (3:49 pm) · 3 replies

Hi,

I don't know if I'm doing something wrong with the code, but when an animated sprite is calling a particle effect as described in tutorials the game freezes temporarily, but that's a problem because player can't see the effect. What could be wrong? some adive to add a particle effect using animated sprites?

This is an example on how I'm calling a particle effect using the position of a static sprite added on the coordinates od an animated sprite.

%explosion = new t2dParticleEffect()
   {
      scenegraph = %this.scenegraph;
      class = "monsterfireone";
   };
   alxPlay(monsterAudio);
   %explosion.loadEffect("~/data/particles/jet2.eff");
   %explosion.setEffectLifeMode("infinite", 1);
   %explosion.setPosition(%brazosBala.getPosition());
   %explosion.playEffect();
   %explosion.mount(%brazosBala, %offsetX = 0, %offsetY = 0);
   %explosion.setPosition(%this.getPosition());
   %explosion.setMountOwned(true);


//this is the code calling first the static sprite and then the particle effect. Is something wrong with it?

if($elegirMonstruo $= "One")
   {
   %brazosBala = new t2dStaticSprite()
   {
      scenegraph = %this.scenegraph;
      class = "brazosBala";
      layer = 3;
   };
   %speed = getRandom(3);
   if(%speed $= 0)
   {
   %brazosBala.setLinearVelocityX(-50);
   }
   else if(%speed $= 1)
   {
   %brazosBala.setLinearVelocityX(-75);
   }
   else if(%speed $= 2)
   {
   %brazosBala.setLinearVelocityX(-100);
   }
   else if(%speed $= 3)
   {
   %brazosBala.setLinearVelocityX(-125);
   }
   %brazosBala.setPosition(monsterG.getPosition());
   %brazosBala.setImageMap(brazosbala_1ImageMap);
   %brazosBala.setSize(12.5, 12.5);
   %brazosBala.setCollisionActive( true, true );
   %brazosBala.setCollisionPhysics(false, false);
   %brazosBala.setCollisionCallback(true);

   %explosion = new t2dParticleEffect()
   {
      scenegraph = %this.scenegraph;
      class = "monsterfireone";
   };
   alxPlay(monsterAudio);
   %explosion.loadEffect("~/data/particles/jet2.eff");
   %explosion.setEffectLifeMode("infinite", 1);
   %explosion.setPosition(%brazosBala.getPosition());
   %explosion.playEffect();
   %explosion.mount(%brazosBala, %offsetX = 0, %offsetY = 0);
   %explosion.setPosition(%this.getPosition());
   %explosion.setMountOwned(true);
   }

Thanks!

#1
08/25/2007 (2:26 am)
"%explosion = new t2dParticleEffect()
{
scenegraph = %this.scenegraph;
class = "monsterfireone";
};
alxPlay(monsterAudio);
%explosion.loadEffect("~/data/particles/jet2.eff");
%explosion.setEffectLifeMode("infinite", 1);
%explosion.setPosition(%brazosBala.getPosition());
%explosion.playEffect();
%explosion.mount(%brazosBala, %offsetX = 0, %offsetY = 0);
%explosion.setPosition(%this.getPosition());
%explosion.setMountOwned(true);"

notice how you have

%explosion.setPosition(%brazosBala.getPosition());
%explosion.setPosition(%this.getPosition());

im thinking its because you tell engine to set the position twice over; but more importantly that in this particular case, the variable, %this, doesnt exist right now

so just try taking the second setPosition() out and tell me what happens
#2
08/25/2007 (12:16 pm)
I've also seen TGB freeze temporarily the first time a particle or sound is played. I have had some luck with playing every particle (hidden) and sound (silently) before the game begins. For some reason, though, even that doesn't ENTIRELY solve the problem.
#3
08/25/2007 (2:59 pm)
You can not precache any sound. Normal sound chips (onboard) are quite restricted on the amount of channels you have ... for that reason they won't work similar to "prebind" media (rendering a texture on screen puts it into VRAM for later usage for example which is a common technique to prevent level startup stutters)
Especially on lower end system this can cause a problem if you had highly compressed OGG which aren't for weak systems that potentially need the CPU to do graphical stuff as well. (intel onboard older than GMA 900)