Diagonal Idle Animation

Started by Armageddon, Tue 10/07/2012 01:09:33

Previous topic - Next topic

Armageddon

My character walks in all 8 directions, like The Dig I'd very much like him to revert to the left-down/right-down whatever idle I have, so even if you would downwards he'll turn back to a diagonal direction when still.

Also I'm having a bit of a problem with my mouse, for some reason when I left click to interact with a hotspot it doesn't do anything it just walks me there.

Code: AGS
function on_mouse_click(MouseButton button) // called when a mouse button is clicked. button is either LEFT or RIGHT
{
  if (IsGamePaused() == 1)
  {
    //Game is paused, so do nothing on any mouse click
  }
  else
  {
    if (button == eMouseLeft)
    {
      //left mouse button
      if (GetLocationType(mouse.x, mouse.y) == eLocationNothing)
      {
        //not over hotspot so walk
        ProcessClick(mouse.x, mouse.y, eModeWalkto);
      }
      else
      {
        //over a hotspot/object etc
        if (mouse.Mode==eModeUseinv)
        {
          //using inventory on hotspot
          ProcessClick(mouse.x, mouse.y, eModeUseinv);
        }
        else
        {
          //not using inventory, so Interact
          ProcessClick(mouse.x, mouse.y, eModeInteract);
        }
      }  
    }
    else if (button == eMouseRight)
    {
      //right mouse button
      if (mouse.Mode==eModeUseinv)
      {
        //inventory item out, so cancel it
        mouse.Mode=eModeLookat;
      }
      else
      {
        //no inventory item out, so look
        ProcessClick(mouse.x, mouse.y, eModeLookat);
      }
    }
    else if (button == eMouseWheelNorth)
    {
      //mouse wheel up
    }
    else if (button == eMouseWheelSouth)
    {
      //mouse wheel down
    }
  }
}


I think this happened when I removed my inventory GUI. Also I have my cursor graphic change when I open up a menu GUI, it works when I open the menu but when I close it it takes a while to change back, I also tried changing it to if the game is paused or not it would change the cursor, it takes even longer to change back after closing the menu.

Code: "AGS"
  if (IsGamePaused() == 1)
  {
    mouse.UseModeGraphic(eModePointer);
  }
  if (IsGamePaused() == 0)
  {
    mouse.UseModeGraphic(eModeInteract);
  }

I tried putting this in repeatedly executed but it kept spamming the normal graphic over the highlight graphic when over a hotspot causing a glitched cursor.

Also these are probably simple, how do you turn off the cursor? I have a paused game screen and I don't want a cursor there, or for cutscenes, it has the hourglass I guess I could make that invisible. And how can I have music pause when the game is paused?

Thanks.

Khris

#1
I don't understand your first sentence at all.

Regarding the rest, mouse.UseModeGraphic() doesn't change the mode, just the sprite it uses. So you're basically setting the current cursor mode's graphic to eModeInteract's graphic whenever you pause, then unpause the game.
You need:
Code: ags
// above repeatedly_execute_always
bool was_paused;
int prev_mode;

  // inside repeatedly_execute_always
  if (IsGamePaused() && !was_paused) {
    // game just went paused
    prev_mode = mouse.Mode;
    mouse.Mode = eModePointer;
  }
  else if (!IsGamePaused() && was_paused) {
    // game pause just ended
    mouse.Mode = prev_mode;
  }
  // store current state for next loop
  was_paused = IsGamePaused();
(We need to use rep_ex_always because rep_ex isn't called during blocking events, afaik.)

In order to debug the on_mouse_click code, put Display commands in there to find out which part is called and what the relevant variables' values are.

In order to hide the mouse, do... wait for it...
Spoiler
Code: ags
  mouse.Visible = false;
[close]

Armageddon

#2
Sorry for the dumb question. :(

What I mean is, in The Dig there are walk directions pointing up, down, left, right, up-right, up-left, down-right, and down-left. Based on where you click it will use on of those walk animations obviously. So when you walk directly left and come to a full stop after the walking is over you will either turn and face the direction left-down(diagonal) or face left-up depending on where you clicked, if it was slightly above or below where the player character was originally standing.

I hope that explains it.

EDIT: Also I can't find anything about making custom room transitions. I have the BlackBoxOut transition but I need it to be a BlackBoxIn thing.

Khris

Ah, I see. Well, just go at it step by step. We'll need the position of the click in relation to the player, so store that in two global ints:
Code: ags
  // inside on_mouse_click
  mouse_offset_x = mouse.x - (player.x - GetViewportX());
  mouse_offset_y = mouse.y - (player.y - GetViewportY());


The next thing is very similar to the mouse cursor stuff:
Code: ags
// above rep_ex
bool was_moving;

  // inside rep_ex
  if (!player.Moving && was_moving) {
    int l == player.Loop;
    if (l == 0) { if (mouse_offset_x < 0) l = 6; else l = 4; }
    if (l == 1) { if (mouse_offset_y < 0) l = 7; else l = 6; }
    if (l == 2) { if (mouse_offset_y < 0) l = 5; else l = 4; }
    if (l == 3) { if (mouse_offset_x < 0) l = 7; else l = 5; }
    player.Loop = l;
  }
  was_moving = player.Moving;


To make a custom room transition: you can't like add your own to the existing ones and have it be called automatically. Again, think about this step by step: The room is supposed to fade out when the character leaves the room, and supposed to fade in after they got to a new room and the before fadein events have run.
The obvious place for the first part is on_event/eEventLeaveRoom. What you do is turn on a GUI with a transparent DynamicSprite as background, then in a loop, change the sprite and set it as GUI background until the GUI is all black. Then the room change occurs, with the transition set to "instant".
Now you need a way to figure out that a room change occured. Conveniently, rep_ex isn't executed during the before fadein event, so again, we're back at checking a variable inside it. This time we store player.Room at the end, then check if (player.Room != last_room). If that's true, set last_room to player.Room and start changing the DynamicSprite back to a transparent one.
In theory you don't even need to turn off the GUI if it is set to not clickable.

Armageddon

#4
Thank you very much Khris, it works very well but now that I have imported all the sprites and set up the views I have a problem. When I try to walk diagonally it only uses the diagonal loops in the view for turning, it doesn't actually use it as a walking animation.

EDIT: I also think I may have misunderstood what to make a global int? I made the mouse_offset_x/y global integers and it works fine. I also have the weirdest thing happening, if I'm walking left and then click right the character always turns up and around instead of looking down and around like when I'm walking right and click to the left.

Armageddon

No one has any ideas how to enable diagonal walking? I have the use loops 4-7 as diagonal walking views enabled and all. I've even tried it without Khris' code and it won't work.

Crimson Wizard

Quote from: Armageddon on Fri 13/07/2012 00:14:47
No one has any ideas how to enable diagonal walking? I have the use loops 4-7 as diagonal walking views enabled and all. I've even tried it without Khris' code and it won't work.
As far as I know, there is "Diagonal Loops" setting in Character's properties. But it should be enabled by default...

Khris

Quote from: Armageddon on Tue 10/07/2012 22:31:22I also have the weirdest thing happening, if I'm walking left and then click right the character always turns up and around instead of looking down and around like when I'm walking right and click to the left.
Seems like AGS always turns the character clockwise if they make a 180° turn. Not that weird, is it?

Also, what CW said. And my code shouldn't affect walking at all, it only changes the loop after the character has stopped walking.

Crimson Wizard

Quote from: Khris on Fri 13/07/2012 00:32:55
Quote from: Armageddon on Tue 10/07/2012 22:31:22I also have the weirdest thing happening, if I'm walking left and then click right the character always turns up and around instead of looking down and around like when I'm walking right and click to the left.
Seems like AGS always turns the character clockwise if they make a 180° turn. Not that weird, is it?
I remember at one instance I had to override this behavior by writing my own turn function, because character turned his head only, and it looked like he's breaking his own neck :D

Armageddon

I've double checked the Diagonal Loops setting many times. I guess the clockwise turn is fine. Also I've noticed the if I click up and to the left of the character to walk, when he finishes walking he turns on looks up and to the right every time.

SMF spam blocked by CleanTalk