Author Topic: Diagonal Idle Animation  (Read 535 times)  Share 

Armageddon

  • Likes apples and nuts
Diagonal Idle Animation
« on: 10 Jul 2012, 01:09 »
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: Adventure Game Studio
  1. function on_mouse_click(MouseButton button) // called when a mouse button is clicked. button is either LEFT or RIGHT
  2. {
  3.   if (IsGamePaused() == 1)
  4.   {
  5.     //Game is paused, so do nothing on any mouse click
  6.   }
  7.   else
  8.   {
  9.     if (button == eMouseLeft)
  10.     {
  11.       //left mouse button
  12.       if (GetLocationType(mouse.x, mouse.y) == eLocationNothing)
  13.       {
  14.         //not over hotspot so walk
  15.         ProcessClick(mouse.x, mouse.y, eModeWalkto);
  16.       }
  17.       else
  18.       {
  19.         //over a hotspot/object etc
  20.         if (mouse.Mode==eModeUseinv)
  21.         {
  22.           //using inventory on hotspot
  23.           ProcessClick(mouse.x, mouse.y, eModeUseinv);
  24.         }
  25.         else
  26.         {
  27.           //not using inventory, so Interact
  28.           ProcessClick(mouse.x, mouse.y, eModeInteract);
  29.         }
  30.       }  
  31.     }
  32.     else if (button == eMouseRight)
  33.     {
  34.       //right mouse button
  35.       if (mouse.Mode==eModeUseinv)
  36.       {
  37.         //inventory item out, so cancel it
  38.         mouse.Mode=eModeLookat;
  39.       }
  40.       else
  41.       {
  42.         //no inventory item out, so look
  43.         ProcessClick(mouse.x, mouse.y, eModeLookat);
  44.       }
  45.     }
  46.     else if (button == eMouseWheelNorth)
  47.     {
  48.       //mouse wheel up
  49.     }
  50.     else if (button == eMouseWheelSouth)
  51.     {
  52.       //mouse wheel down
  53.     }
  54.   }
  55. }

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: Text
  1.   if (IsGamePaused() == 1)
  2.   {
  3.     mouse.UseModeGraphic(eModePointer);
  4.   }
  5.   if (IsGamePaused() == 0)
  6.   {
  7.     mouse.UseModeGraphic(eModeInteract);
  8.   }
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

  • Evil Dark Emperor Death-Kill
    • Lifetime Achievement Award Winner
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with translating
    •  
Re: Diagonal Idle Animation
« Reply #1 on: 10 Jul 2012, 01:55 »
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: Adventure Game Studio
  1. // above repeatedly_execute_always
  2. bool was_paused;
  3. int prev_mode;
  4.  
  5.   // inside repeatedly_execute_always
  6.   if (IsGamePaused() && !was_paused) {
  7.     // game just went paused
  8.     prev_mode = mouse.Mode;
  9.     mouse.Mode = eModePointer;
  10.   }
  11.   else if (!IsGamePaused() && was_paused) {
  12.     // game pause just ended
  13.     mouse.Mode = prev_mode;
  14.   }
  15.   // store current state for next loop
  16.   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...
Code: Adventure Game Studio
  1.   mouse.Visible = false;
« Last Edit: 10 Jul 2012, 02:07 by Khris »
http://whathaveyoutried.com/

The other day on yahoo answers:
"Can you print colored images with black ink? If so tell me how please Thanx Kimberly"

Armageddon

  • Likes apples and nuts
Re: Diagonal Idle Animation
« Reply #2 on: 10 Jul 2012, 02:20 »
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.
« Last Edit: 10 Jul 2012, 03:23 by Armageddon »

Khris

  • Evil Dark Emperor Death-Kill
    • Lifetime Achievement Award Winner
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with translating
    •  
Re: Diagonal Idle Animation
« Reply #3 on: 10 Jul 2012, 10:27 »
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: Adventure Game Studio
  1.   // inside on_mouse_click
  2.   mouse_offset_x = mouse.x - (player.x - GetViewportX());
  3.   mouse_offset_y = mouse.y - (player.y - GetViewportY());

The next thing is very similar to the mouse cursor stuff:
Code: Adventure Game Studio
  1. // above rep_ex
  2. bool was_moving;
  3.  
  4.   // inside rep_ex
  5.   if (!player.Moving && was_moving) {
  6.     int l == player.Loop;
  7.     if (l == 0) { if (mouse_offset_x < 0) l = 6; else l = 4; }
  8.     if (l == 1) { if (mouse_offset_y < 0) l = 7; else l = 6; }
  9.     if (l == 2) { if (mouse_offset_y < 0) l = 5; else l = 4; }
  10.     if (l == 3) { if (mouse_offset_x < 0) l = 7; else l = 5; }
  11.     player.Loop = l;
  12.   }
  13.   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.
http://whathaveyoutried.com/

The other day on yahoo answers:
"Can you print colored images with black ink? If so tell me how please Thanx Kimberly"

Armageddon

  • Likes apples and nuts
Re: Diagonal Idle Animation
« Reply #4 on: 10 Jul 2012, 22:31 »
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.
« Last Edit: 11 Jul 2012, 01:25 by Armageddon »

Armageddon

  • Likes apples and nuts
Re: Diagonal Idle Animation
« Reply #5 on: 13 Jul 2012, 00:14 »
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

  • AGS Project Admins
  • not et suppotreD
    • I can help with translating
    •  
Re: Diagonal Idle Animation
« Reply #6 on: 13 Jul 2012, 00:30 »
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

  • Evil Dark Emperor Death-Kill
    • Lifetime Achievement Award Winner
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with translating
    •  
Re: Diagonal Idle Animation
« Reply #7 on: 13 Jul 2012, 00:32 »
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.
http://whathaveyoutried.com/

The other day on yahoo answers:
"Can you print colored images with black ink? If so tell me how please Thanx Kimberly"

Crimson Wizard

  • AGS Project Admins
  • not et suppotreD
    • I can help with translating
    •  
Re: Diagonal Idle Animation
« Reply #8 on: 13 Jul 2012, 00:44 »
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.
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

  • Likes apples and nuts
Re: Diagonal Idle Animation
« Reply #9 on: 13 Jul 2012, 00:47 »
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.