Animation window not realed to room?

Started by CNC_Acolythe, Sat 27/09/2014 11:25:51

Previous topic - Next topic

CNC_Acolythe

Hi!
I want to create various windows with animations that will be improving atmosfere of the game and will not be bounded to certain room.  I will use simple example - player will have stone and the knife in inventory. By combining them, he will sharpen the knife. And when he does this, there would appear window with a short animation of sharpening, no matter the room where the player is.

My idea was to create sort of "animation character" that I will place in the middle of the room and then quickly animate with desired view and then make him "go away" again. I dont want to bind this action to certain place and apart of creating objects of the same name in every possible room I'm  out of ideas. Any sugestion on how to do this? I have feeling there must be simpler solution than with my "animation character", but I don't see it...

Thanks for advice!
"Holy central unit!"

Khris

#1
A character is exactly what you would use, yes.
Code: ags
function ShowAnimation(int which) {
  cAnim.ChangeRoom(player.Room);
  cAnim.Transparency = 0;
  cAnim.LockView(ANIMATIONS);
  cAnim.Animate(which, 5, eOnce, eBlock);
  cAnim.Transparency = 100;
  cAnim.UnlockView();
}


Not sure how it could be even simpler than that.
(Also, not exactly an advanced question :))

Edit: fixed code
Also, don't know why this is supposed to be clumsy; sure, using a GUI and a button will also work. Btw, my code needs some additional lines if the game has scrolling rooms to center the character, something one admittedly doesn't have to do with a GUI.

CNC_Acolythe

Thanks. I just wanted to be sure I'm not overlooking anything. And yes, I guess it not advanced question, when I think of it now... :undecided:
"Holy central unit!"

Crimson Wizard

#3
Umm, Khris, Character does not have Visible property (btw this reminds me to add a feature suggestion...).
To hide the character you need to either:
1. Move it to different room.
2. Move it outside room bounds (e.g. to coordinates (-1000, -1000)).
3. Assign it a fully transparent view.
4. Set cAnim.Transparency = 100;

Alternatively you could use a GUI with animated button placed upon it:
Code: ags

gAnim.Visible = true;
btnCutscene.Animate(VIEW, LOOP, SPEED, eOnce);
Wait(TIME_TO_WAIT);
gAnim.Visible = false;

CNC_Acolythe

Quote from: Crimson Wizard on Sat 27/09/2014 12:03:49

Alternatively you could use a GUI with animated button placed upon it:


- that is what I had in mind! Using cahracter is kind of "clumsy" - also Im not sure how to make him to be "on top" of everything. Animated button should be just perfect. Gonna try it now. Thank you, Crimson Wizard.
"Holy central unit!"

Gurok

Regarding Khris' code, you could also use cAnim.on = false or cAnim.Transparency = 100 in place of cAnim.Visible = false

Code: ags
    function ShowAnimation(int which) {
      cAnim.ChangeRoom(player.Room);
      cAnim.on = true;
      cAnim.LockView(ANIMATIONS);
      cAnim.Animate(which, 5, eOnce, eBlock);
      cAnim.on = false;
      cAnim.UnlockView();
    }
[img]http://7d4iqnx.gif;rWRLUuw.gi

Crimson Wizard

#6
I guess there's a way to calculate loop's length, in time, to write a "universal" function like Khris did for the character.

Code: ags

function ShowAnimation(int which, int anim_speed) {
    int frame_cnt = Game.GetFrameCountForLoop(ANIMATIONS_VIEW, which);
    int frame_time = 0;
    int i = 0;
    while (i < frame_cnt) {
        ViewFrame* vf = Game.GetViewFrame(ANIMATIONS_VIEW, which, i);
        // I hope I do this right... someone needs to check this out!
        frame_time += vf.Speed * anim_speed * GetGameSpeed();
        i++;
    }

    gAnim.Visible = true;
    btnCutscene.Animate(ANIMATIONS_VIEW, which, anim_speed, eOnce);
    Wait(frame_time);
    gAnim.Visible = false;
}



Quote from: Gurok on Sat 27/09/2014 12:14:39
Regarding Khris' code, you could also use cAnim.on = false or cAnim.Transparency = 100 in place of cAnim.Visible = false
"Character.on" is a deprecated API; the less you use them the better ;).

CNC_Acolythe

So it is advanced after all! :-D :-D I like Crimson Wizards code, going to try it right now! :)
"Holy central unit!"

CNC_Acolythe

#8
One last thing - when I use the button solution, animation displays correctly, however due to the fact that Im using the button to do this, it is "greyed out" durig animation. I believe it is a work of "Wait" function. Can it be bypassed with a timer?

Edit:
Well, I used the timer and when the rest of the code is moved to "repeatedly execute" section, it works just fine. Last thing that remains is controls - can i somehow disable game controls while this GUI is displayed?
"Holy central unit!"

Slasher

Go to the game general settings, go to 'Visual', select 'when player interface is disabled...' and select "Display normally'

The button (and all gui's) will not grey out.


monkey0506

Quote from: Crimson Wizard on Sat 27/09/2014 12:19:01
Quote from: Gurok on Sat 27/09/2014 12:14:39
Regarding Khris' code, you could also use cAnim.on = false or cAnim.Transparency = 100 in place of cAnim.Visible = false
"Character.on" is a deprecated API; the less you use them the better ;).

That's not actually entirely true. Character.on is a property which predates AGS 2.7 (and the introduction of most of the OO style structures), but it was never supported for general purpose usages. CJ discouraged using it simply because it was untested and not guaranteed to work correctly in all cases if toggled within a single room, but the engine relies on it for rooms where the player isn't shown (and conversely as well). It has been used by module authors in high profile modules like CharacterControl without any reports (AFAIK) of it malfunctioning.

Since it was never officially supported for use, it could theoretically be removed altogether, but in reality that would break existing scripts unnecessarily. We could provide a Visible attribute which would internally reference the same thing, presumably with no other changes than the imports. Arguing that it shouldn't be used at this point though is like saying Character.x, Character.y, Character.z, Mouse.x, Mouse.y, and many other properties should be avoided.

CNC_Acolythe

#11
Quote from: slasher on Sat 27/09/2014 13:03:42
Go to the game general settings, go to 'Visual', select 'when player interface is disabled...' and select "Display normally'

The button (and all gui's) will not grey out.



Yes, I know about this option, but I would like to have other options greyed out during animations and such...

Edit:

Khris:
Character option can be suerly used, and it would solve my "greyed-out" problem. By the "clumsy" I meant the fact, that it would need to be centered in every room, plus I would have to make sure that the character will be always on top of everything - in case there are any walkbehind areas and such... It can be done, but for now animated GUI seems easier. But we'll see. :D
"Holy central unit!"

SMF spam blocked by CleanTalk