The Dink Network

How to...

October 21st 2010, 02:59 PM
burntree.gif
hell7fire1
Peasant He/Him Botswana
It's like that. 
How do I make a sprite change frames by the number of times dink hits the sprite
October 21st 2010, 03:07 PM
dinkdead.gif
sp_pframe(sprite, frame) will change the frame, so you just need to add a variable that keeps count of how many times you hit it.

//for example
void hit (void)
{
  &counter += 1;
  if (&counter >= 5)
  {
    sp_pframe(&current_sprite, 3);
  }
  if (&counter >= 10)
  {
    sp_pframe(&current_sprite, 7);
  }
  //etc etc etc etc etc
}
October 22nd 2010, 05:29 AM
wizardb.gif
Kyle
Peasant He/Him Belgium
 
Make sure the sprite isn't an animated sprite to start with though, if that's what you're going for.

Also, Sparrow's script will eventually not work anymore when the sprite runs out of frames. You would have to reset it to 1 at some point
October 22nd 2010, 11:00 AM
custom_iplaydink.gif
iplaydink
Peasant He/Him Sweden
Hmm.. 
@Kyle

It does not!As long as you don't set it to a frame that doesn't exist. It sets the sp_pframe to a specific value when the variable is more (or equal to) an value. What you are thinking about kyle would be something like:

void main(void)
{
    int &counter;
}
void hit(void)
{
    &counter += 1;
    sp_pframe(&current_sprite, &counter);    
}

which would stop working when &counter is more than the number of frames in the seq, and could be fixed with a
if(&counter == 10) &counter = 1;
between &counter += 1 and sp_pframe.


@Sparrowhawks:

Wouldn't that make the sprite flicker between frames, if even only for a so short time that it's impossible to see? Wouldn't it be better to write:
.
.
.
if(&counter >= 5)
{
    if(&counter < 10)
    {
        //desired frame here.
    }
}
.
.
.


October 23rd 2010, 08:36 AM
wizardb.gif
Kyle
Peasant He/Him Belgium
 
Yes, for some reason I assumed that was what Sparrow was going for in the first place and I somehow missed the static numbers in the code snippet.