Adventure Game Studio

AGS Support => Modules, Plugins & Tools => Topic started by: edmundito on Sun 01/03/2015 19:27:23

Title: MODULE: TWEEN 2.1.0 with AGS 3.4.0 support!
Post by: edmundito on Sun 01/03/2015 19:27:23
Latest Version is 2.2.0 - See the Tween 2.2.0 thread (https://www.adventuregamestudio.co.uk/forums/index.php?topic=57315.0) for more details!

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 "inbetweening". It's typically used in Adobe Flash to indicate interpolation of an object from one keyframe to another.

Instead of depending on while loops everywhere in your code:

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


You can do this:

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


Notable games using the tween module include: A Golden Wake, Primordia, the Ben Jordan series, and Gemini Rue.

---

Tween 2.x is a huge upgrade from Tween 1.x. It is closer to the vision I had when I first started working on the first Tween module while still keeping the simplicity of the original.

Major changes include:

New Easing Functions

The new easing functions are based on common easing functions used by other tween modules. These include elastic, bouncing, backing out, etc.
You can see a demo of these at http://easings.net (http://easings.net).

Stop Individual Tweens

You can now stop individual tweens:

cEgo.TweenPosition(2.0, 100, 100, eEaseLinearTween, eReverseRepeatTween);

// ... Later:
cEgo.StopTweenPosition();


Tween by SPEED

You can tween ANYTHING by speed instead of seconds as well. This allows you to move objects at a constant speed regardless of where they are.

Start Delay

You can delay the start of any tween allowing you to create interesting effects.

Convenient fade out and fade in tween functions

gIconbar.TweenFadeOut(0.5);

Custom Tweens

For the advanced users who like to have control, you can also create your own custom tweens that take advantage of the module's easing and timing functions. This also allows you to create tweens for drawing surfaces.


function TweenIndyMapLine(int fromX, int fromY, int toX, int toY) {
  Tween.IncreaseGameSpeed();

  Tween myTweenX;
  Tween myTweenY;
  myTweenX.Init(3.0, fromX, toX);
  myTweenY.Init(3.0, fromY, toY);
  int previousX = FloatToInt(myTweenX.FromValue);
  int previousY = FloatToInt(myTweenY.FromValue);
  int drawColor = Game.GetColorFromRGB(255, 0, 0);
 
  while (myTweenX.IsPlaying() || myTweenY.IsPlaying()) {
    myTweenX.Update();
    myTweenY.Update();
   
    DrawingSurface *surface = Room.GetDrawingSurfaceForBackground();
    surface.DrawingColor = drawColor;
    surface.DrawLine(previousX, previousY, myTweenX.Value, myTweenY.Value, 3);
    surface.Release();
   
    previousX = myTweenX.Value;
    previousY = myTweenY.Value;
   
    Wait(1);
  }
   
  Tween.RestoreGameSpeed();
}


No longer compatible with AGS 2.x!

If you would like to use the tween module with an AGS 2 game, then get the Tween 1.x module (http://www.adventuregamestudio.co.uk/forums/index.php?topic=38015.0).

---

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

Documentation:
http://ags-tween.readthedocs.io/en/v2.1.0/

Support Chat:
https://discord.gg/vmuCyWX

Issues and Feature Planning:
https://github.com/edmundito/ags-tween/issues

Special Thanks to:
Tzachs for expanding the original module to support most of the properties in AGS, Grundislav and Dualnames for promoting and creating very inspiring work with the original module, jwalts37 who I met in person at GDC 2014 and told me how much he liked the module, Vince Twelve for showing me some advanced code that was the inspiration for Tween 2's startDelay, Calin Leafshade for giving me more insight into scripting best practices, and everyone in the forum for reporting problems and making games with this.
Title: Re: MODULE: TWEEN 2! (2.0.0)
Post by: Ibispi on Sun 01/03/2015 20:49:42
Tween module is my favorite module! Congratulations on new version release! :-)
Thanks Edmundito, and everyone else who worked on it!
Title: Re: MODULE: TWEEN 2! (2.0.0)
Post by: Dualnames on Mon 02/03/2015 01:08:52
Stickied, Tween module is the single best thing out of an AGS script.
Title: Re: MODULE: TWEEN 2! (2.0.0)
Post by: ollj on Fri 05/06/2015 09:18:38
history and maths of tweening: https://www.youtube.com/watch?v=zLh0K1PdUbc
Title: Re: MODULE: TWEEN 2! (2.0.0)
Post by: Julius Dangerous on Wed 24/06/2015 12:33:27
Awesome!
Title: Re: MODULE: TWEEN 2! (2.0.1)
Post by: edmundito on Sun 12/07/2015 23:27:46
2.0.1 now available with a minor fix related to Character, Object, or GUI FadeIn FadeOut tweens. Thanks to Blackthorne!
Title: Re: MODULE: TWEEN 2! (2.0.1)
Post by: Blackthorne on Fri 17/07/2015 14:22:18
Quote from: Edmundito on Sun 12/07/2015 23:27:46
2.0.1 now available with a minor fix related to Character, Object, or GUI FadeIn FadeOut tweens. Thanks to Blackthorne!

No problem! Thanks to YOU!!

Bt
Title: Re: MODULE: TWEEN 2! (2.0.1)
Post by: ollj on Sun 19/07/2015 14:56:01
The GUI."resize" tween pivots to the top left ot the GUI, and i assume thats the same for dynamicsprites...

having a function that somehow manages to set the scaling pivot, the point of the image that doesnt move when resizing, percentually with a float. That is whats missing for me.
Title: Re: MODULE: TWEEN 2! (2.0.1)
Post by: Julius Dangerous on Wed 29/07/2015 12:39:31
Thanks! :P
Title: Re: MODULE: TWEEN 2! (2.0.1)
Post by: Cassiebsg on Wed 29/07/2015 19:07:33
Many many thanks for creating and sharing this! (nod)(nod)(nod)
I need to give this one a try, love the possibilities already! (laugh)(roll)
Title: Re: MODULE: TWEEN 2! (2.0.1)
Post by: edmundito on Sat 10/10/2015 22:04:58
Quick update: I've set up a public Skype chat if you'd like to have some live support or chat about tween module techniques:

Tween Module Skype Chat Group: https://join.skype.com/CsrRAc17CJIb

(Also updated the main post with this info!)
Title: Re: MODULE: TWEEN 2! (2.0.1)
Post by: edmundito on Sun 11/10/2015 05:52:25
Quote from: ollj on Sun 19/07/2015 14:56:01
The GUI."resize" tween pivots to the top left ot the GUI, and i assume thats the same for dynamicsprites...

having a function that somehow manages to set the scaling pivot, the point of the image that doesnt move when resizing, percentually with a float. That is whats missing for me.

Oh yeah, that's a fairly advanced issue that maybe I can look into including into the module. I've added it as an idea in the github issue tracker:
https://github.com/edmundito/ags-tween/issues/3

In the meantime, here is a function that can resize the GUI with the pivot, you can update it to fit the object that you need:

Add this to your Global Script or a Module Script:
int TweenSizeFromPivot(this GUI*, Pivot pivot, float timing, int toWidth, int toHeight, TweenEasingType easingType, TweenStyle style, float startDelay, TweenTimingType timingType) {
  int toX = this.X;
  int toY = this.Y;

  if (pivot == ePivotTopCenter || pivot == ePivotMiddleCenter || pivot == ePivotBottomCenter) {
    toX += (this.Width - toWidth) / 2;
  } else if (pivot == ePivotTopRight || pivot == ePivotMiddleRight || pivot == ePivotBottomRight) {
    toX += (this.Width - toWidth);
  }
 
  if (pivot == ePivotMiddleLeft || pivot == ePivotMiddleCenter || pivot == ePivotMiddleRight) {
    toY += (this.Height - toHeight) / 2;
  } else if (pivot == ePivotBottomLeft || pivot == ePivotBottomCenter || pivot == ePivotBottomRight) {
    toY += (this.Height - toHeight);
  }
 
  int sizeDuration = this.TweenSize(timing, toWidth, toHeight, easingType, eNoBlockTween, startDelay, timingType);
  int positionDuration = this.TweenPosition(timing, toX, toY, easingType, eNoBlockTween, startDelay, timingType);
  if (style == eBlockTween) {
    WaitForLongest(sizeDuration, positionDuration);
  }
}


Add this to your Global Script Header or a Module Header:
enum Pivot {
    ePivotTopLeft,
    ePivotTopCenter,
    ePivotTopRight,
    ePivotMiddleLeft,
    ePivotMiddleCenter,
    ePivotMiddleRight,
    ePivotBottomLeft,
    ePivotBottomCenter,
    ePivotBottomRight
};

import int TweenSizeFromPivot(this GUI*, Pivot pivot, float timing, int toWidth, int toHeight, TweenEasingType easingType=Tween_EASING_TYPE_GUI, TweenStyle style=Tween_STYLE_GUI, float startDelay=Tween_START_DELAY_GUI, TweenTimingType timingType=Tween_TIMING_GUI);


Simple Usage:
gIconbar.TweenSizeFromPivot(eBottomRight, 0.5, 160, 120);
Title: Re: MODULE: TWEEN 2! (2.0.1)
Post by: Monsieur OUXX on Fri 18/12/2015 17:36:00
I didn't find how to set a tween based on speed rather than duration, as advertised (I'm sure it's here somewhere but it eludes me).

EDIT: OK, found it: TimingType
Title: Re: MODULE: TWEEN 2! (2.0.1)
Post by: Monsieur OUXX on Fri 18/12/2015 18:03:28
Suggestion for next version:

Make it easier to bind together some tweens (one for X, and one for Y, and why not one for altitude, etc.), based on a shared movement speed.

Let me explain what I mean:

Imagine you have a room Object that you want to move at a given speed. Then you can simply use Object.TweenPosition along with TimingType == eTweenSpeed. The module takes charge of calculating the duration matching that speed, and then updates both X and Y automatically with the appropriate ratio applied to each of them (namely: cos, and sin).

However, now, imagine you want to do the same with your very own abstract Tween object, that you will use for drawing onto surfaces. Very much the same as you do in the "Indy map example" in the first post. Then it's a pain to calculate the duration and the ratios by hand. You didn't have to do it in your example because you simply set the same duration (3.0) to both X and Y.

It's not too hard to do it, but if you created a class for an abstract (X,Y) tween (not relying on an actual AGS Object or Character or whatnot) that would be really cool...
Title: Re: MODULE: TWEEN 2! (2.0.1)
Post by: edmundito on Sat 19/12/2015 03:57:26
Quote from: Monsieur OUXX on Fri 18/12/2015 18:03:28
Suggestion for next version:

Make it easier to bind together some tweens (one for X, and one for Y, and why not one for altitude, etc.), based on a shared movement speed.

Let me explain what I mean:

Imagine you have a room Object that you want to move at a given speed. Then you can simply use Object.TweenPosition along with TimingType == eTweenSpeed. The module takes charge of calculating the duration matching that speed, and then updates both X and Y automatically with the appropriate ratio applied to each of them (namely: cos, and sin).

However, now, imagine you want to do the same with your very own abstract Tween object, that you will use for drawing onto surfaces. Very much the same as you do in the "Indy map example" in the first post. Then it's a pain to calculate the duration and the ratios by hand. You didn't have to do it in your example because you simply set the same duration (3.0) to both X and Y.

It's not too hard to do it, but if you created a class for an abstract (X,Y) tween (not relying on an actual AGS Object or Character or whatnot) that would be really cool...

Hey, interesting idea, glad to see that some of the new fancy features are getting pushed to the limit.

I was wondering two things:

Is this specific to creating custom Tweens or for other types of combinations as well? Could you give me some examples of things you were trying to do with speed that the module did not support?

Can tell me more about "altitude" and how it relates in AGS?
Title: Re: MODULE: TWEEN 2! (2.0.1)
Post by: Monsieur OUXX on Sat 19/12/2015 12:12:41
Quote from: Edmundito on Sat 19/12/2015 03:57:26
Is this specific to creating custom Tweens or for other types of combinations as well? Could you give me some examples of things you were trying to do with speed that the module did not support? Can tell me more about "altitude" and how it relates in AGS?

It's strictly for Tweens, and as I said you already did it inside the module to manage X and Y simultaneously in objects (Chracters, Guis, etc.) that have both a X and a Y.
I gave an example: manage my own objects that have a X and a Y property.
Don't stay focused on "altitude". It could be anything, for example a "Z" if you manage a 3-dimensional space.

Long things short: a way to tween more than 1 property at once, based on the speed. It's alreayd possible in the module, but one has to understand how to relate speed to FPS. A tiny utility class would make that easier.

Title: Re: MODULE: TWEEN 2! (2.0.2)
Post by: daneeca on Thu 21/04/2016 18:54:09
Hi!
I wanted to try it, but I got an error message:
"Tween.asc(212): Error (line 212): 'max' is a global var; cannot use as name for local"

Maybe It's not working with AGS 3.4.0.6? :/
Title: Re: MODULE: TWEEN 2! (2.0.2)
Post by: edmundito on Thu 21/04/2016 19:23:27
Quote from: daneeca on Thu 21/04/2016 18:54:09
Hi!
I wanted to try it, but I got an error message:
"Tween.asc(212): Error (line 212): 'max' is a global var; cannot use as name for local"

Maybe It's not working with AGS 3.4.0.6? :/

Hi! I have actually not tested it on 3.4 yet, but maybe I should. I'll take a look at it this weekend. I've created a bug report in:
https://github.com/edmundito/ags-tween/issues/7

If anyone else is testing in 3.4.x, please let me know what works for you and what doesn't. If you'd like to see some new tween supported for 3.4 features please let me know as well.
Title: Re: MODULE: TWEEN 2! (2.0.2)
Post by: Crimson Wizard on Thu 21/04/2016 20:15:58
AGS 3.4.0.6 does not have any "max" global variables.
daneeca, do you have any modules before Tween which has such variable declared in the header? Or any game object named "max"? Or variable called "max" on the Global Variables pane?
Title: Re: MODULE: TWEEN 2! (2.0.2)
Post by: daneeca on Thu 21/04/2016 22:49:10
I have the Smooth Scrolling & Parallax module and a global variable named "max".
So, maybe this is the problem. If I rename the max global variable it probably will work. I'll try it tomorrow and report the results.

Thanks for the help!
Title: Re: MODULE: TWEEN 2! (2.0.2)
Post by: daneeca on Sun 24/04/2016 15:37:27
Yes, that was the problem. It's working now. This module is awesome! :)
Thanks again and sorry for my clumsiness.
Title: Re: MODULE: TWEEN 2! (2.0.2)
Post by: edmundito on Sat 30/04/2016 18:00:47
Quote from: daneeca on Thu 21/04/2016 22:49:10
I have the Smooth Scrolling & Parallax module and a global variable named "max".
So, maybe this is the problem. If I rename the max global variable it probably will work. I'll try it tomorrow and report the results.

Thanks for the help!

daneeca, Were you able to test this?
Title: Re: MODULE: TWEEN 2! (2.0.2)
Post by: Crimson Wizard on Mon 02/05/2016 01:00:12
Edmundito, daneeca just replied 1 post above:

Quote from: daneeca on Sun 24/04/2016 15:37:27
Yes, that was the problem. It's working now. This module is awesome! :)
Thanks again and sorry for my clumsiness.

Apparently there was simply a global variable of that name.
Title: Re: MODULE: TWEEN 2! (2.0.2)
Post by: edmundito on Sun 08/05/2016 18:24:17
Quote from: Crimson Wizard on Mon 02/05/2016 01:00:12
Edmundito, daneeca just replied 1 post above:

Quote from: daneeca on Sun 24/04/2016 15:37:27
Yes, that was the problem. It's working now. This module is awesome! :)
Thanks again and sorry for my clumsiness.

Apparently there was simply a global variable of that name.

Oooh, totally missed that Page 2!
Title: Re: MODULE: TWEEN 2! (2.0.2)
Post by: Amayirot Akago on Sun 05/06/2016 14:45:00
For a beginning AGS'er like myself, this module is a life-saver :D
Title: Re: MODULE: TWEEN 2! (2.0.2)
Post by: Stupot on Mon 06/06/2016 08:46:37
Just a thought. Sorry if this has already been suggested (or even done?) but has anyone thought about integrating SSH's credits module with the Tween module? I've noticed a few games lately with lovely smooth things happening on screen but then a really (relatively) jerky final credits.
Title: Re: MODULE: TWEEN 2! (2.0.2)
Post by: edmundito on Sat 03/09/2016 00:22:37
Need help? I started a chat room on Discord:
https://discord.gg/vmuCyWX

(also updated the main post with the chat link.)
Title: Re: MODULE: TWEEN 2! (2.0.2)
Post by: .M.M. on Wed 23/11/2016 14:33:56
Hi, this is absolutely great module with endless count of useful applications! Hovewer, I have a problem with one type of tween, TweenViewport. For some reason, I can't get it to work as I need. This is the code:
Code (ags) Select

     Display("Viewport: %d,%d", GetViewportX(), GetViewportY());
     mc_x = character[i_start].x-System.ViewportWidth/2;
     mc_y = character[i_start].y-System.ViewportHeight/2;
     TweenViewport(20.0, mc_x, mc_y, eEaseOutSineTween, eBlockTween, 0.0, eTweenSpeed);
     //SetViewport(mc_x, mc_y);
     Display("Move x,y: %d,%d[Viewport: %d,%d", mc_x, mc_y, GetViewportX(), GetViewportY());

It should move the camera so that the character with ID i_start is in the centre of viewport. However, it moves the Viewport in completely different direction. In my test, ViewportX;Y is 680;320 at start, 60;60 at end. Variables mc_x;y are 480;60 - I don't see any simple way how to make a vector out of these variables.
This code runs exactly as it should be:
Code (ags) Select

     Display("Viewport: %d,%d", GetViewportX(), GetViewportY());
     SetViewport(mc_x, mc_y);
     Display("Move x,y: %d,%d[Viewport: %d,%d", mc_x, mc_y, GetViewportX(), GetViewportY());

ViewportX;Y is 680;320 at start, 480;60 at end. Variables mc_x;y 480;60.
Title: Re: MODULE: TWEEN 2! (2.0.2)
Post by: edmundito on Wed 23/11/2016 18:17:11
Hi .M.M, thanks for posting. You're right, there is a bug with TweenViewport in 2.0.x and I should have released a patch sooner.

Basically, it's Tweening the X part of the viewport with the Y value. In the meantime, you can open the Tween.asc file and find the line:

else if (this.Type == _eTweenViewport) {

And then modify the next lines to look correct. Here is the change that I made that has not been released:

https://github.com/edmundito/ags-tween/commit/99c36adc60f10a793c49115467ee088de514791e?diff=split

If you're not familiar with Github, red means old, and Green means new, the stronger highlights within the lines indicate exactly what I changed.
Title: Re: MODULE: TWEEN 2.1.0 with AGS 3.4.0 support!
Post by: edmundito on Mon 05/12/2016 00:36:01
Hey everyone, thanks for all the feedback! I finally got around to supporting many features found in 3.3.0 and 3.4.0. This is the first major release since the release of 2.0.0!

More details can be round in the release notes:
https://github.com/edmundito/ags-tween/releases/tag/v2.1.0

And yeah, it fixes the TweenViewport bug!
Title: Re: MODULE: TWEEN 2.1.0 with AGS 3.4.0 support!
Post by: Amayirot Akago on Thu 08/12/2016 09:01:04
Yaaaaay! :D This is sure to come in handy if and when I ever get around to making another AGS game!
Title: Re: MODULE: TWEEN 2.1.0 with AGS 3.4.0 support!
Post by: Crimson Wizard on Thu 08/12/2016 16:16:34
I found this demo that may be used to visualize object tweening across 2d plane: http://gizma.com/easing
Title: Re: MODULE: TWEEN 2.1.0 with AGS 3.4.0 support!
Post by: .M.M. on Sun 11/12/2016 11:12:49
Thank you for the reply, fix and the whole TWEEN module! :)
Title: Re: MODULE: TWEEN 2.1.0 with AGS 3.4.0 support!
Post by: Danvzare on Mon 12/12/2016 12:01:52
Quote from: .M.M. on Sun 11/12/2016 11:12:49
Thank you for the reply, fix and the whole TWEEN module! :)
Same here. Thanks so very much for the TWEEN module as a whole.
It's definitely one of the best modules for AGS, and a real life saver. :-D
Title: Re: MODULE: TWEEN 2.1.0 with AGS 3.4.0 support!
Post by: eri0o on Sun 17/12/2017 15:02:42
Hey! I am trying to understand Custom Tweens. I have a int variable that I want to tween. The code below is pseudo-code to explain this idea. How to do this?

Code (ags) Select
int aVariable;

game_start(){
  aVariable = 10;
}

void something(){
  aVariable.Tween(1.5, 70, eEaseLinearTween, eNoBlockTween);
}
Title: Re: MODULE: TWEEN 2.1.0 with AGS 3.4.0 support!
Post by: eri0o on Tue 27/08/2019 14:11:44
If someone came here, the new version is here -> https://www.adventuregamestudio.co.uk/forums/index.php?topic=57315.0
Title: Re: MODULE: TWEEN 2.1.0 with AGS 3.4.0 support!
Post by: eri0o on Mon 01/03/2021 14:01:34
Edmundito stealthly updated the top post on this thread, now my previous comment is wrong!