Adventure Game Studio

AGS Support => Modules, Plugins & Tools => Topic started by: edmundito on Tue 04/04/2023 01:35:15

Title: Tween 2.3.0 with AGS 3.6.0 support!
Post by: edmundito on Tue 04/04/2023 01:35:15
About

The AGS Tween Module allows you to programmatically interpolate many of the AGS properties (objects, characters, regions, viewport, audio, GUI, GUI controls, etc.) over time in amazing ways. The term tween comes from the computer animation term inbetweening (https://en.wikipedia.org/wiki/Inbetweening).

(https://i.imgur.com/m5p5Tah.gif)

Don't depend on using while loops everywhere in your code to move something:

while (gIconbar.Y > -gIconbar.Height) {
  gIconbar.Y = gIconbar.Y - 1;
  Wait(1);
}

With the Tween module, can do graceful things like this:

gIconbar.TweenY(0.5, -gIconbar.Height, eEaseInBackTween);

Notable games using the tween module include Guard Duty, Lamplight City, Unavowed, Future Flashback, and Rosewater.

What are you waiting for? Start using the Tween module today!

---
What's new in 2.3.0?

TL;DR: This is a great new release that supports the new features in AGS 3.6.0, adds support for Point object tweens, and the long overdue support for Overlay X and Y. This module is compatible with AGS 3.5 or above.


Added Overlay TweenX, TweenY, TweenPosition
3.5.0: Added Point TweenX, TweenY, TweenPosition
3.6.0: Added Character TweenAnimationVolume
3.6.0: Character.TweenScaling is no longer limited by a range of 5-200. Now supports 1-32767
3.6.0: Added GUIControl TweenTransparency
3.6.0: Added Object TweenScaling
3.6.0: Added Overlay Width, Height, Size, and Transparency
Internal: Updated how managed tweens are created to support Point and Overlay tweens
Added function documentation where extra properties such as ManualScaling, Visible are also updated

---

Download from:
https://github.com/edmundito/ags-tween/releases/tag/v2.3.0

Documentation:
https://edmundito.gitbook.io/ags-tween/

Financial Support:
Happy to take tips or donations through my Ko-fi site: https://ko-fi.com/edmundito

Chat in the AGS Discord server:
https://discord.gg/vmuCyWX

Issues and feature planning:
https://github.com/edmundito/ags-tween/issues
Title: Re: Tween 2.3.0 with AGS 3.6.0 support!
Post by: eri0o on Tue 11/04/2023 03:47:44
Tweening Overlays is a god send for my random things! Thank you for this! I can probably now refactor a good portion of my old manamatch (https://github.com/ericoporto/manamatch/blob/main/manamatch/PieceTween.asc) with this! (that code was before there was unlimited overlays too, so it was all using a hackedup software renderer made in script)
Title: Re: Tween 2.3.0 with AGS 3.6.0 support!
Post by: RootBound on Mon 24/04/2023 16:14:05

EDIT: SOLVED - I didn't realize there was an issues page, it was this one: https://github.com/edmundito/ags-tween/issues/2
---------------------------------



Hi @edmundito,

Running AGS 3.6.0, I get the following error:

QuoteTween.asc(751): Error (line 751): undefined symbol 'gui'

This is the code in question (error caused by final line):

function _TweenObject::Step(float amount) {
  switch (this.Type) {
    // GUI step
    case _eTweenGUIPosition:
      if (this.FromValue == this.ToValue) {
        _value = gui[this.RefID].X;
      }


Any idea what the problem is?

Thanks
Title: Re: Tween 2.3.0 with AGS 3.6.0 support!
Post by: RootBound on Tue 02/05/2023 15:29:33
OK, new problem. Can't figure out what I'm doing wrong in my scripting. Goal is to be able to pseudo change speed of tweens (including stopping and resuming) by doing the following:

1. getting the current fraction of tween's duration remaining through customtween.GetTweenProgress() and the current value through customtween.value.

2. stop the tween

3. start a new tween with the value and duration modified based on what was previously elapsed.

This is, however, not working. I have a label displaying the value of customtween.GetTweenProgress(which, if I understand correctly, is supposed to return a float value between 0 and 1), but instead the returned value almost instantaneously climbs to a 10-digit whole integer, and if the tween is paused and unpaused value returns to 0 (integer, not float) and stays there.

Any help would be greatly appreciated.

Here's my code:


Global variables:
-----------------
int Speed = 0
int SpeedChange = 0
float TweenFraction
int CurrentTweenValue


Global script:
--------------

repeatedly_execute_always() {
   Label2.Text = String.Format("Scaling: %d", CurrentTweenValue);
   Label3.Text = String.Format("Progress: %d", TweenFraction);
}

function btnSpeedUp_OnClick(GUIControl *control, MouseButton button) {
  if (Speed < 3){
    Speed ++;
    SpeedChange = 1;
  }
}

function btnSpeedDown_OnClick(GUIControl *control, MouseButton button) {
  if (Speed > 0){
    Speed --;
    SpeedChange = 1;
  }
}


room script:
-----------

Tween IncreaseScaling;
float Duration;

function room_AfterFadeIn() {
  SetTimer(1,GetGameSpeed()/40);
}

function repeatedly_execute_always() {
  CurrentTweenValue = IncreaseScaling.Value;
  TweenFraction = IncreaseScaling.GetProgress();
 
  if (IsTimerExpired(1))  {
    SetTimer(1, GetGameSpeed()/40);
    if (IncreaseScaling.IsPlaying())  {
      IncreaseScaling.Update();
    }
    cTree.Scaling = IncreaseScaling.Value;
  }
  if (Speed == 0) {
     cTree.StopMoving();
     IncreaseScaling.Stop(ePauseTween);
  }
  if (Speed == 1){
     Duration = 3.0;
  }
  if(Speed == 2){
    Duration = 2.0;
  }
  if(Speed == 3){
    Duration = 1.0;
  }
  if(SpeedChange == 1) {
    readonly float CurrentProgress = IncreaseScaling.GetProgress();
    SpeedChange = 0;
    cTree.StopMoving();
    if (Speed !=0) {
      cTree.SetWalkSpeed(Speed*2, Speed*2);
      IncreaseScaling.Init(Duration - (Duration*CurrentProgress), CurrentTweenScaling, 300, eEaseInCircTween, eNoBlockTween);
    }
    cTree.Walk(500, 400, eNoBlock, eAnywhere);
   
  }


Thank you very much for any responses.

EDIT: added into this post a block of code I forgot to include in the above section.
Title: Re: Tween 2.3.0 with AGS 3.6.0 support!
Post by: Crimson Wizard on Thu 04/05/2023 18:01:43
@Gilbert or @Dualnames , perhaps this may be stickied and replace the 2.2.0 sticky topic (https://www.adventuregamestudio.co.uk/forums/modules-plugins-tools/module-tween-2-2-2-with-ags-3-5-0-support!)?
Title: Re: Tween 2.3.0 with AGS 3.6.0 support!
Post by: Gilbert on Fri 05/05/2023 06:26:13
Done. :)
Title: Re: Tween 2.3.0 with AGS 3.6.0 support!
Post by: edmundito on Mon 08/05/2023 16:12:05
@RootBound

Quote from: RootBound on Tue 02/05/2023 15:29:33OK, new problem. Can't figure out what I'm doing wrong in my scripting. Goal is to be able to pseudo change speed of tweens (including stopping and resuming) by doing the following:

1. getting the current fraction of tween's duration remaining through customtween.GetTweenProgress() and the current value through customtween.value.

2. stop the tween

3. start a new tween with the value and duration modified based on what was previously elapsed.

This is, however, not working. I have a label displaying the value of customtween.GetTweenProgress(which, if I understand correctly, is supposed to return a float value between 0 and 1), but instead the returned value almost instantaneously climbs to a 10-digit whole integer, and if the tween is paused and unpaused value returns to 0 (integer, not float) and stays there.

Any help would be greatly appreciated.


First, you can use the tween-provided function SecondsToLoops(1.0) to convert seconds to game loops instead of using GetGameSpeed() / 40. There's also a tween-provided function called SetTimerWithSeconds where youc can provide the number of seconds directly.

The problem I see in your code is that you're calling Update() only when the timer is expired:

  if (IsTimerExpired(1))  {
    SetTimer(1, GetGameSpeed()/40);
    if (IncreaseScaling.IsPlaying())  {
      IncreaseScaling.Update();
    }
    cTree.Scaling = IncreaseScaling.Value;
  }

Update needs to be called always because it only moves the tween one step on every loop. What I would recommend is do all your logic at the top of the function and then update the tween:

function repeatedly_execute_always() {
  if (IncreaseScaling.IsPlaying())  {
    IncreaseScaling.Update();
  }
  // Update object logic
  // Reset tween logic
}
Title: Re: Tween 2.3.0 with AGS 3.6.0 support!
Post by: RootBound on Mon 08/05/2023 18:35:26
@edmundito Thank you, I will try these things out soon and see what happens.
Title: Re: Tween 2.3.0 with AGS 3.6.0 support!
Post by: AndreasBlack on Tue 29/08/2023 14:29:17
I'm unsure where to ask this, but this code doesn't seem to get any result anymore in AGS 3.6..
It doesn't give me any error's or something like that. It just doesn't pan out to the side's anymore. It was a nice effect to use! :~(

function region1_WalksOnto()
{
if (Ambient_Wind.IsPlaying)

{
Ambient_Wind.TweenPanning(0.3, 100);    //Right or Left side of the room

}


}



function region2_WalksOnto()
{
if (Ambient_Wind.IsPlaying)

{
Ambient_Wind.TweenPanning(0.3, -100);     //Right or Left side of the room
}


}

Title: Re: Tween 2.3.0 with AGS 3.6.0 support!
Post by: Crimson Wizard on Tue 29/08/2023 14:40:21
Quote from: AndreasBlack on Tue 29/08/2023 14:29:17I'm unsure where to ask this, but this code doesn't seem to get any result anymore in AGS 3.6..
It doesn't give me any error's or something like that. It just doesn't pan out to the side's anymore. It was a nice effect to use!

What kind of a sound file are you using for this?
There's a known issue that stereo sounds can no longer be panned in 3.6.0, only mono ones.
Mostly this is because the stereo panning was not really a "panning" in previous versions, but another effect which coincidentally worked as if it were panning.
Title: Re: Tween 2.3.0 with AGS 3.6.0 support!
Post by: AndreasBlack on Tue 29/08/2023 18:21:45
Quote from: Crimson Wizard on Tue 29/08/2023 14:40:21
Quote from: AndreasBlack on Tue 29/08/2023 14:29:17I'm unsure where to ask this, but this code doesn't seem to get any result anymore in AGS 3.6..
It doesn't give me any error's or something like that. It just doesn't pan out to the side's anymore. It was a nice effect to use!

What kind of a sound file are you using for this?
There's a known issue that stereo sounds can no longer be panned in 3.6.0, only mono ones.
Mostly this is because the stereo panning was not really a "panning" in previous versions, but another effect which coincidentally worked as if it were panning.

I've been using both waves and ogg's this particular one seemed to be ogg 32bit floating stereo! So i'm converting it to Mono now, hold your butts! (nod)

Edit: Ogg mono, 32bit, works! Stereo would be nice ofc, but whatever it's just a ambient wind sound, not that important!
Title: Re: Tween 2.3.0 with AGS 3.6.0 support!
Post by: eri0o on Tue 29/08/2023 19:53:54
The issue is upstream of us, here:

https://github.com/icculus/mojoAL/issues/12

There is an open PR there that adds an extension to mojoAL that would make it possible to do it. The discussion there explain the details.
Title: Re: Tween 2.3.0 with AGS 3.6.0 support!
Post by: AndreasBlack on Tue 29/08/2023 20:06:47
Quote from: eri0o on Tue 29/08/2023 19:53:54The issue is upstream of us, here:

https://github.com/icculus/mojoAL/issues/12

There is an open PR there that adds an extension to mojoAL that would make it possible to do it. The discussion there explain the details.

Eri0o have you forgot who i am? I'm the guy that almost didn't get your experimental gamepad to work! (laugh) How's that going anyway any progress? I'll pass your suggestion, but thanks for letting me know! Mono works fine as for now. It's not that important since it's just an ambient wind sound! (nod)
Title: Re: Tween 2.3.0 with AGS 3.6.0 support!
Post by: Crimson Wizard on Tue 29/08/2023 20:07:31
Quote from: eri0o on Tue 29/08/2023 19:53:54There is an open PR there that adds an extension to mojoAL that would make it possible to do it.

If it's this PR (https://github.com/icculus/mojoAL/pull/13) then it does a logically different effect, and personally I believe it should not be activated by "Panning" function in AGS.
Title: Re: Tween 2.3.0 with AGS 3.6.0 support!
Post by: eri0o on Tue 29/08/2023 20:54:17
Quote from: AndreasBlack on Tue 29/08/2023 20:06:47How's that going anyway any progress?

The work for the gamepad has been merged in ags4 and should be in the next alpha release of ags4! There is still work to do in that front, hopefully people play with it a bit there, and we see the things to add on top of the gamepad api, and what has to be improved/clarified then.
Title: Re: Tween 2.3.0 with AGS 3.6.0 support!
Post by: edmundito on Wed 11/10/2023 16:02:31
For anyone intersted in providing donations or tips, I've updated the first post with my Ko-fi site: https://ko-fi.com/edmundito - This is greatly appreciated and may encourage me to keep working on the module!
Title: Re: Tween 2.3.0 with AGS 3.6.0 support!
Post by: AndreasBlack on Wed 11/10/2023 19:18:36
Hey Edmundito, it would be nice if one could tween the animationdelay of objects & characters in floats. To be able to speed stuff up like Wheels, fans, various mechnical parts instead of using the view editor or manually Photoshop perhaps or code it (i had no clue where to begin). Just a suggestion!

Duration time for how long GUI's stay on screen is another one. Atm the very friendly eri0o cranked out something that does it for me, but it should be optional in the tween module in the future to set desired duration, since if i'm not mistakening you can do that in other tweens of the module. I use your module all the time btw, keep up the good work! (nod) 

Title: Re: Tween 2.3.0 with AGS 3.6.0 support!
Post by: kursh on Wed 15/11/2023 16:06:42
Its amazingggggg, i was turning crazy to make a transition between 2 songs.. this is simply aaamaazingggg!!!!!!!!!!  8-0

thanks to the autor/s
Title: Re: Tween 2.3.0 with AGS 3.6.0 support!
Post by: FortressCaulfield on Sat 15/06/2024 18:23:41
Someone recommended me this mod for moving chars or objects in a smooth arc and I don't understand how I would make it do that. Any help?
Title: Re: Tween 2.3.0 with AGS 3.6.0 support!
Post by: Crimson Wizard on Sat 15/06/2024 18:32:46
Quote from: FortressCaulfield on Sat 15/06/2024 18:23:41Someone recommended me this mod for moving chars or objects in a smooth arc and I don't understand how I would make it do that. Any help?

I am not an expert in this module, but I imagine that the solution could be to process 2 coordinates (x,y) using two separate tweens, one linear and another non-linear with "InOut" effect (for returning back). For example: eEaseInOutCircTween sounds like something suitable.
https://edmundito.gitbook.io/ags-tween/basic/enums[]

EDIT: hmm, no, I am mistaken. This easing does not do what I thought. Maybe it's not doable with 1 tween for a coordinate, but 2 sequential tweens, unless someone knows better.
Title: Re: Tween 2.3.0 with AGS 3.6.0 support!
Post by: Snarky on Sat 15/06/2024 20:02:26
Yeah, I think CW is right that this would be the way to do it with the module. For example, to do a "throw a ball" (parabolic) arc you could tween the X-position with linear easing for 1 second, while tweening the Y-position up and then down (for 0.5 seconds each) using quadratic easing.

But personally, I think once you're having to combine tweens this way, syncing the timings and all that, it's easier to just do it yourself, so in most cases I would probably program the movement directly. You simply have to use the same equation you would use to draw a graph of the curve. (So, for a parabolic arc, y = ax^2 + bx + c.)
Title: Re: Tween 2.3.0 with AGS 3.6.0 support!
Post by: edmundito on Mon 17/06/2024 15:29:25
Quote from: FortressCaulfield on Sat 15/06/2024 18:23:41Someone recommended me this mod for moving chars or objects in a smooth arc and I don't understand how I would make it do that. Any help?

Can you explain the "arc" you are trying to create?

What you need to do is have two tweens. One that moves the X and the other the Y. Here's an example of how to do a circular arc:

player.TweenX(0.5, player.x + 100, eEaseLinearTween, eNoBlockTween);
player.TweenY(0.5, player.y + 100, eEaseOutQuadTween, eBlockTween);

The movement would be similar to this: https://easings.net/#easeOutQuad

If you want the object to go up and then down, then you write the code in two parts:
player.TweenX(0.5, player.x + 50, eEaseLinearTween, eNoBlockTween);
player.TweenY(0.5, player.y + 100, eEaseOutQuadTween, eBlockTween);
player.TweenX(0.5, player.x + 50, eEaseLinearTween, eNoBlockTween);
player.TweenY(0.5, player.y - 100, eEaseOutQuadTween, eBlockTween);
Title: Re: Tween 2.3.0 with AGS 3.6.0 support!
Post by: FortressCaulfield on Wed 19/06/2024 15:17:49
Okay, so it can do what I need. That arc is perfect as it is for someone thrown off a moving vehicle. Thanks!
Title: Re: Tween 2.3.0 with AGS 3.6.0 support!
Post by: Baguettator on Sat 18/01/2025 13:36:13
Hi there, is this module going to be updated with AGS 4.0 compatibility ? And is there any release date ? Just to know, no pressure :)

Thanks for the work anyway !