Animating a character depending on x,y coordinates

Started by xenogia, Thu 04/06/2009 10:35:10

Previous topic - Next topic

xenogia

Hi Guys,

I am trying to make a character animate when you walk across the screen, the scene specifically is when you walk past x co-ord 439 and another character looks up, and when you walk away the other character looks away.  Anyhoo, it isn't quite working.. Have a look at the code and tell me what you think?

Code: ags

if (cMichael.x > 439) {
    if (cMonic.Frame == 295) {
      cMonic.ChangeView(36);
      cMonic.Animate (0, 3, eOnce, eNoBlock, eForwards);
    }
  }
  
  if (cMichael.x < 439) {
    if (cMonic.Frame == 304) {
      cMonic.ChangeView(36);
      cMonic.Animate (0, 3, eOnce, eNoBlock, eBackwards);
    }
  }

Gilbert

One problem is, what are frames 295 and 304 of CMonic? Are you sure that these frames are being displayed at some game loops where you want the animations to be played?

Khris

Does the character animate at all? What happens and what doesn't?
Also, where did you put that code? I assume inside the room's repeatedly_execute, which is properly linked to the room's event?

The code looks OK, apart from cMichael1.x == 439 not being handled.

Edit after I saw Gilbet's post:
You have to compare cMonic.Frame to the frame number, not the sprite's number.

xenogia

Okay I change the frame sections as follows:

Code: ags

if (cMichael.x > 439) {
    if (cMonic.Frame == 0) {
      cMonic.ChangeView(36);
      cMonic.Animate (0, 3, eOnce, eNoBlock, eForwards);
    }
  }
  
  if (cMichael.x < 439) {
    if (cMonic.Frame == 14) {
      cMonic.ChangeView(36);
      cMonic.Animate (0, 3, eOnce, eNoBlock, eBackwards);
    }
  }


Now this exactly what happens when you first go into the room cMonic is looking at a computer.  cMonic isn't animating at this point.  As cMichael walks past x.439, cMonic looks up as if being distracted.  Now if you walk away from cMonic and go to any co-ords before 439, cMonic will then look back down at the computer.

It is all in the one the loop just played forwards and backwards,  doing the Frame thing didn't work to well then either.  What do people think the best way to code such a thing is?

xenogia

#4
Code: ags

 if (cMichael.x > 439) {
    if ((cMonic.View == 36) && (cMonic.Frame == 0)) {
      cMonic.ChangeView(36);
      cMonic.Animate (0, 2, eOnce, eNoBlock, eForwards);
      
    }
  }
  
  if (cMichael.x < 439) {
    if ((cMonic.View == 36) && (cMonic.Frame == 14)) {
       cMonic.ChangeView(36);
      cMonic.Animate (0, 2, eOnce, eNoBlock, eBackwards);
      
    }


I even tried this option but what happens is that it seems to reverse the process, and the first you walk up to cMonic the character doesn't look up at all.  But once you walk away cMonic then looks up making the whole process go in reverse.

EDIT: Got it to work, added in a (cMonic.Animating == false) and it seems to resolve my issues.

Khris

You're checking if the View is 36, and if it is, setting it to 36. That doesn't make any sense.
Don't guess.

What is cMonic's view when he just sits there?
Also, again, where did you put that code, inside what function?

I'm not sure what's going on, but I'd code it like this, assuming that initially, cMonic uses Loop 0, Frame 0 of View 36:
Code: ags
  if (cMichael.x > 439 && cMonic.Frame == 0) cMonic.Animate (0, 2, eOnce, eNoBlock, eForwards);
  else if (cMichael.x < 440 && cMonic.Frame == 14) cMonic.Animate (0, 2, eOnce, eNoBlock, eBackwards);

xenogia

Repeatedly execute is where it is sitting.

And thanks about the ChangeView (36) don't know why I put that in there.
Anyhoo, I got it to work :)

SMF spam blocked by CleanTalk