Forum

animating a sprite.

Discuss programming in the QuakeC language.

Moderator: InsideQC Admins

animating a sprite.

Postby ceriux » Fri Feb 04, 2011 5:09 am

this is what i did. im pretty sure it should work.

anyone tell me what im doin wrong?

Code: Select all
void() anim_smoke1 =
{
           self.frame = 1;
      if (time == time +1)
      {
         self.frame = self.frame + 1;
      }
      else if (self.frame == 16)
      {
         self.frame = 1;
      }
};

void() efx_smoke1 =
{
   self.movetype = MOVETYPE_NONE;
   self.velocity = '0 0 0';
   self.touch = SUB_Null;
   setmodel (self, "progs/smoke01.spr");
   self.solid = SOLID_NOT;
   anim_smoke1 ();
};



tried this too:

Code: Select all
void() anim_smoke1 =
{
           self.frame = 1;
      if (time == time +1 && self.frame == 1)
      {
         self.think = self.frame +1;
      }
      else if (self.frame == 16)
      {
         
         self.nextthink = self.frame = 1;
      }
};
Last edited by ceriux on Fri Feb 04, 2011 5:15 am, edited 1 time in total.
User avatar
ceriux
 
Posts: 2223
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA

Postby r00k » Fri Feb 04, 2011 5:14 am

i think you have to set a nextthink in there somewhere...

Code: Select all
void() efx_smoke1 =
{
   self.movetype = MOVETYPE_NONE;
   self.velocity = '0 0 0';
   self.touch = SUB_Null;
   setmodel (self, "progs/smoke01.spr");
   self.solid = SOLID_NOT;
   self.think =  anim_smoke1;
   self.nextthink = time + 1;
}
Last edited by r00k on Fri Feb 04, 2011 5:16 am, edited 2 times in total.
r00k
 
Posts: 1110
Joined: Sat Nov 13, 2004 10:39 pm

Postby ceriux » Fri Feb 04, 2011 5:15 am

r00k wrote:i think you have to set a nextthink in there somewhere...


sorry updated my post before i saw you posted. i had that thought.

also tried changing the self.think to self.nextthink. no go.
Last edited by ceriux on Fri Feb 04, 2011 5:16 am, edited 1 time in total.
User avatar
ceriux
 
Posts: 2223
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA

Postby r00k » Fri Feb 04, 2011 5:16 am

updated my post ^^ lol
this should constantly call the anim function every second that the entity is relinked.
Last edited by r00k on Fri Feb 04, 2011 5:17 am, edited 1 time in total.
r00k
 
Posts: 1110
Joined: Sat Nov 13, 2004 10:39 pm

Postby ceriux » Fri Feb 04, 2011 5:17 am

ah thank you, going to try that again.

still a no =/
User avatar
ceriux
 
Posts: 2223
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA

Postby leileilol » Fri Feb 04, 2011 5:25 am

think before you nextthink. nextthink needs time. You can not change time in qc. You can only change what you think of time.

Code: Select all
void() anim_smoke1 =
{
     if(self.frame < 16) self.frame = self.frame + 1;
     else remove(self);
     self.think = anim_smoke1;
     self.nextthink = time + 0.1;
};
i should not be here
leileilol
 
Posts: 2783
Joined: Fri Oct 15, 2004 3:23 am

Postby ceriux » Fri Feb 04, 2011 5:34 am

doesnt seem to work leilei. but im going to mess with your code too. (it just removes the sprite on spawn)

i figured out if i change time + 0.1 to just 1 , its there but it still sits at the same frame.
User avatar
ceriux
 
Posts: 2223
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA

Postby leileilol » Fri Feb 04, 2011 5:38 am

ceriux wrote:doesnt seem to work leilei. but im going to mess with your code too. (it just removes the sprite on spawn)


My code assumed a explosion animation. If you use a bit of THINK POWER you could change that "else remove(self); " to "else self.frame = 0". WOW IT LOOPS!!!

also try debugging with s_explod.spr instead. trying to help over the internet on a possible malformed sprite file is even more a pain
i should not be here
leileilol
 
Posts: 2783
Joined: Fri Oct 15, 2004 3:23 am

Postby ceriux » Fri Feb 04, 2011 5:40 am

leileilol wrote:
ceriux wrote:doesnt seem to work leilei. but im going to mess with your code too. (it just removes the sprite on spawn)


My code assumed a explosion animation. If you use a bit of THINK POWER you could change that "else remove(self); " to "else self.frame = 0". WOW IT LOOPS!!!




i did use my "think power" and did that right as you were posting =)

it still only seems to play two frames removes it's self then spawns again in a loop. either that or i just cant see it cause the last few frames are working correctly...

Code: Select all

void() anim_smoke1 =
{
   
       if(self.frame < 15) self.frame = self.frame + 1;
     else self.frame =0;
     self.think = anim_smoke1;
     self.nextthink = time + 0.1;
};

void() efx_smoke1 =
{
   self.movetype = MOVETYPE_NONE;
   self.velocity = '0 0 0';
   self.touch = SUB_Null;
   setmodel (self, "progs/smoke01.spr");
   self.solid = SOLID_NOT;
   self.think =  anim_smoke1;
   self.nextthink = time + 0.1;
} ;


im recompiling the map with the entity not half way in the chimney see what happens.

edit: it's playing them all from what i can tell. time to try n fix that sprite.
User avatar
ceriux
 
Posts: 2223
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA

Postby r00k » Fri Feb 04, 2011 5:47 am

It's been a long time since i messed with sprites, this is old code I had for my flame thrower...

Code: Select all
.float flametime;
void() flame_touch =
{
   if (other.classname == "Torch") return;//no fire-vs-fire

   if ((other == self.owner) && ( (self.nextthink - time) > 0.6 ) ) return;

   if (other.classname=="player")
   {
      other.deathtype = "torch";
      T_Damage (other, self, self.owner, 20);
   }

   sound (self, CHAN_WEAPON, "hknight/hit.wav", 1, ATTN_NORM);
   BecomeExplosion();
};

void ()

flame_think =
{
   local entity t1;

   if (pointcontents(self.origin) == CONTENT_WATER)
   {
      remove (self);
      return;
   }

   if (pointcontents(self.origin) == CONTENT_SLIME)
   {
      remove (self);
      return;
   }

   // flame has died remove ent.
   if (self.frame >= 5)
   {
      remove(self);
      return;
   }

   //create more fire!
   //just for looks
   t1           = spawn();
   t1.classname = "Torch";
   t1.owner     = self;
   t1.solid     = SOLID_NOT;
   t1.movetype  = self.movetype;

   setorigin (t1, self.origin);
   setmodel  (t1, "progs/s_explod.spr");

   t1.velocity  = (self.velocity * 0.5);
   t1.frame     = self.frame;
   t1.think     = SUB_Remove;
   t1.nextthink = time + 0.2;

   if ((self.flametime - time) < 0.6)
   {
      self.frame = self.frame + 0.5;
   }

   self.think     = flame_think;
   self.nextthink = time + (sys_ticrate);
};

void() W_FireFlame =
{
   local entity  flame;

   if (self.health<1) return;

   //spit out bubbles if underwater
   if (self.waterlevel > 1)
   {
      flame           = spawn();
      flame.solid     = SOLID_BBOX;
      flame.movetype  = MOVETYPE_FLY;
      makevectors       (self.v_angle);
      flame.velocity  = self.velocity;
      flame.velocity  = aim(self, 10000);
      flame.velocity  = flame.velocity * 100;
      flame.angles    = vectoangles(flame.velocity);
      flame.flags     = FL_ITEM;
      flame.frame     = 0;
      flame.touch     = SUB_Null;
      flame.think     = SUB_Remove;
      flame.nextthink = time + 1;

      setmodel (flame, "progs/s_bubble.spr");
      sound    (self, CHAN_WEAPON, "fish/death.wav", 1, ATTN_NORM);
      setsize  (flame, '0 0 0', '0 0 0');
      setorigin(flame, self.origin + (v_forward*16) + '0 0 16');
      self.attack_finished = time + 0.8;
      return;
   }

   flame           = spawn();
   flame.classname = "Torch";
   flame.owner     = self;
   flame.solid     = SOLID_BBOX;
   flame.movetype  = MOVETYPE_FLY;
   flame.effects   = EF_DIMLIGHT;
   flame.frame     = 0;
   makevectors       (self.v_angle);
   flame.velocity  = self.velocity;
   flame.velocity  = aim(self, 10000);
   flame.velocity  = (self.velocity * 0.6) + (flame.velocity * 300);
   flame.angles    = vectoangles(flame.velocity);
   flame.flags     = FL_ITEM;
   flame.touch     = flame_touch;
   flame.think     = flame_think;
   flame.nextthink = time + (sys_ticrate);
   flame.flametime = time + (sys_ticrate + 0.05);

   sound    (self, CHAN_WEAPON, "weapons/ax1.wav", 0.4, ATTN_NORM);
   setmodel (flame, "progs/s_explod.spr");
   setsize  (flame, '0 0 0', '0 0 0');
   setorigin(flame, self.origin + (v_forward*16) + '0 0 16');
};

r00k
 
Posts: 1110
Joined: Sat Nov 13, 2004 10:39 pm

Postby ceriux » Fri Feb 04, 2011 5:48 am

quick question. what's the difference in .spr and .spr32?
User avatar
ceriux
 
Posts: 2223
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA

Postby Sajt » Fri Feb 04, 2011 5:53 am

spr32 is a new format supporting full colour images with alpha channels and stuff.
F. A. Špork, an enlightened nobleman and a great patron of art, had a stately Baroque spa complex built on the banks of the River Labe.
Sajt
 
Posts: 1215
Joined: Sat Oct 16, 2004 3:39 am

Postby ceriux » Fri Feb 04, 2011 6:43 am

oooo sounds like ill be upgrading. agh... as long as fitzquake supports it... i wish DP would just fix it's hlbsp =/
User avatar
ceriux
 
Posts: 2223
Joined: Sat Sep 06, 2008 3:30 pm
Location: Indiana, USA

Postby frag.machine » Fri Feb 04, 2011 10:19 pm

Code: Select all
// WARNING: UNTESTED, USE AT YOUR OWN RISK!!!!!!11ONE.

Code:
void() anim_smoke1 =
{
  self.frame = self.frame + 1;
  if (self.frame < 16)
  {
    self.think = anim_smoke1;
  }
  else
  {
    self.think = SUB_Remove;
  }

  self.nextthink = time + 0.1; 
};

// this is kinda weird, because smoke is supposed to
// be spawned by something burning or exploding. As
// is, this smoke sprite will always appears at (0,0,0).
// You may want to fix this.
// Also, may look cool if the smoke goes up a little
// bit while animating, so you may consider adding:
// self.velocity = '0 0 1';
void() efx_smoke1 =
{
  precache_model ("progs/smoke01.spr");
  setmodel (self, "progs/smoke01.spr");
  self.frame = 0;
  self.solid = SOLID_NOT;
  self.movetype = MOVETYPE_NONE;
  self.think = anim_smoke1;
  self.nextthink = time + 0.1;
};
I know FrikaC made a cgi-bin version of the quakec interpreter once and wrote part of his website in QuakeC :) (LordHavoc)
User avatar
frag.machine
 
Posts: 2090
Joined: Sat Nov 25, 2006 1:49 pm


Return to QuakeC Programming

Who is online

Users browsing this forum: No registered users and 1 guest