(SOLVED) Animating my character picking up objects and combining them

Started by viktor, Thu 21/01/2021 09:25:34

Previous topic - Next topic

viktor

I have two questions about animating my character sprite.

1. When my character picks up an object is it possible to make an object dissapear on a certain frame of animation? The way things are now I have to animate the character stretching out his arm, then make the object not visible and then animate the character again tucking his arm back. Is there an easier way? Can I just animate one loop and make the object disappear midway?

2. When my character combines or fidles with objects I made a simple animation of him doing that. But I animated him doing that in all 4 directions depending what direction he is facing when you order him to do it. Is there an easy way of animating him without an if statement to check where he is facing every time? That seems to tedious to be honest.
signature" border="0
<a target='_blank' href='https://imgbb.com/'>resurrection pictures for facebook</a>

Crimson Wizard

#1
Quote from: viktor on Thu 21/01/2021 09:25:34
1. When my character picks up an object is it possible to make an object dissapear on a certain frame of animation? The way things are now I have to animate the character stretching out his arm, then make the object not visible and then animate the character again tucking his arm back. Is there an easier way? Can I just animate one loop and make the object disappear midway?

You can launch non-blocking animation, keep waiting in same function, and test for current frame, then do action on necessary frame.
I recently posted an example of the checking for animation to end: https://www.adventuregamestudio.co.uk/forums/index.php?topic=58769.msg636631371#msg636631371
similarily you may test for Character.Frame to see current animation frame.

example
Code: ags

while (player.Animating)
{
     if (player.Frame == 5)
     {
          // remove object
     }
     Wait(1); // wait minimal time to update the game in background and keep checking if it's still animating
};


Quote from: viktor on Thu 21/01/2021 09:25:34
2. When my character combines or fidles with objects I made a simple animation of him doing that. But I animated him doing that in all 4 directions depending what direction he is facing when you order him to do it. Is there an easy way of animating him without an if statement to check where he is facing every time? That seems to tedious to be honest.

I don't know how exactly your code looks like, but if you make your action views use same rule for loops as normal walking animation (loop 0 for down, loop 1 for left, etc), then you may just call Animate passing current Character.Loop value.

Khris

1. you can add a function to your global script:
Code: ags
// add to global header
import void PickUpObject(Object *obj);

// add to global script
Object* pickedUpObject;

void PickUpObject(Object *obj) {
  pickedUpObject = obj;
  SetTimer(1, 20); // half a second / 4th frame
  player.LockView(PLAYER_TAKE);
  player.Animate(player.Loop, 5, eOnce, eBlock);
  player.UnlockView();
}

// add this inside repeatedly_execute_always()
  if (IsTimerExpired(1)) {
    pickedUpObject.Visible = false;
  }


Now just call it in your room code:  PickUpObject(oPen);

This also solves 2, like CW has explained.

viktor

Wow... It worked. That was simple. I overthunk this way too much. Now all I have to do is figure out Khirs' solution make things easier on me :). But for now at least I know how to make this work. Thank you both :).

But now I hit another snag... For some reason after executing this code my player does not loose the item he is suppose to. player.AddInventor works fine but for some reason player.LoseInventory doesn't.

Nevermind, I figured it out. The game kept adding the inventory item in on every 3rd frame of animation because I put the code in the wrong spot. Fixed now.

Code: ags
function iLighter_OtherClick(){
  if (Verbs.UsedAction(eGA_Open)) {
    player.LockView(VRADAR_COMBINE);
    player.Animate(player.Loop, 5, eOnce, eBlock);
    player.UnlockView();
    player.Say("There, it's open.");
    player.LoseInventory(iLighter);
    player.AddInventory(iOLighter);
  }
}
signature" border="0
<a target='_blank' href='https://imgbb.com/'>resurrection pictures for facebook</a>

SMF spam blocked by CleanTalk