Author Topic: MODULE: TWEEN 2.1.0 with AGS 3.4.0 support!  (Read 10613 times)  Share 

Edmundito

  • Mittens Serf
    • Best Innovation Award Winner 2014, for 'Tween Module'
    •  
    • I can help with scripting
    •  
  • Edmundito worked on a game that was nominated for an AGS Award!
MODULE: TWEEN 2.1.0 with AGS 3.4.0 support!
« on: 01 Mar 2015, 19:27 »
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:
Code: Adventure Game Studio
  1. while (gIconbar.Y > -gIconbar.Height) {
  2.   gIconbar.Y = gIconbar.Y - 1;
  3.   Wait(1);
  4. }

You can do this:
Code: Adventure Game Studio
  1. 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.

Stop Individual Tweens

You can now stop individual tweens:

Code: Adventure Game Studio
  1. cEgo.TweenPosition(2.0, 100, 100, eEaseLinearTween, eReverseRepeatTween);
  2.  
  3. // ... Later:
  4. 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

Code: Adventure Game Studio
  1. 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.

Code: Adventure Game Studio
  1. function TweenIndyMapLine(int fromX, int fromY, int toX, int toY) {
  2.   Tween.IncreaseGameSpeed();
  3.  
  4.   Tween myTweenX;
  5.   Tween myTweenY;
  6.   myTweenX.Init(3.0, fromX, toX);
  7.   myTweenY.Init(3.0, fromY, toY);
  8.   int previousX = FloatToInt(myTweenX.FromValue);
  9.   int previousY = FloatToInt(myTweenY.FromValue);
  10.   int drawColor = Game.GetColorFromRGB(255, 0, 0);
  11.  
  12.   while (myTweenX.IsPlaying() || myTweenY.IsPlaying()) {
  13.     myTweenX.Update();
  14.     myTweenY.Update();
  15.    
  16.     DrawingSurface *surface = Room.GetDrawingSurfaceForBackground();
  17.     surface.DrawingColor = drawColor;
  18.     surface.DrawLine(previousX, previousY, myTweenX.Value, myTweenY.Value, 3);
  19.     surface.Release();
  20.    
  21.     previousX = myTweenX.Value;
  22.     previousY = myTweenY.Value;
  23.    
  24.     Wait(1);
  25.   }
  26.    
  27.   Tween.RestoreGameSpeed();
  28. }

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.

---

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.
« Last Edit: 05 Dec 2016, 00:33 by Edmundito »
Start using the Tween 2 Module!

Ibispi

    • I can help with making music
    •  
    • I can help with play testing
    •  
  • Ibispi worked on a game that was nominated for an AGS Award!
Re: MODULE: TWEEN 2! (2.0.0)
« Reply #1 on: 01 Mar 2015, 20:49 »
Tween module is my favorite module! Congratulations on new version release! :-)
Thanks Edmundito, and everyone else who worked on it!
« Last Edit: 01 Mar 2015, 20:52 by BSP »

Dualnames

  • Local Moderator
  • Rottwheelers
  • Pretty Badass
  • Dualnames worked on a game that was nominated for an AGS Award!Dualnames worked on a game that won an AGS Award!
Re: MODULE: TWEEN 2! (2.0.0)
« Reply #2 on: 02 Mar 2015, 01:08 »
Stickied, Tween module is the single best thing out of an AGS script.
No more military army stuff. I'm alive and back.

Re: MODULE: TWEEN 2! (2.0.0)
« Reply #3 on: 05 Jun 2015, 09:18 »
history and maths of tweening:

Re: MODULE: TWEEN 2! (2.0.0)
« Reply #4 on: 24 Jun 2015, 12:33 »
Awesome!
_______________________________________ ____________________

Edmundito

  • Mittens Serf
    • Best Innovation Award Winner 2014, for 'Tween Module'
    •  
    • I can help with scripting
    •  
  • Edmundito worked on a game that was nominated for an AGS Award!
Re: MODULE: TWEEN 2! (2.0.1)
« Reply #5 on: 12 Jul 2015, 23:27 »
2.0.1 now available with a minor fix related to Character, Object, or GUI FadeIn FadeOut tweens. Thanks to Blackthorne!
Start using the Tween 2 Module!

Blackthorne

  • Infamous Quests
  • Blackthorne worked on a game that was nominated for an AGS Award!Blackthorne worked on a game that won an AGS Award!
Re: MODULE: TWEEN 2! (2.0.1)
« Reply #6 on: 17 Jul 2015, 14:22 »
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
-----------------------------------
"Enjoy Every Sandwich" - Warren Zevon

http://www.infamous-quests.com

Re: MODULE: TWEEN 2! (2.0.1)
« Reply #7 on: 19 Jul 2015, 14:56 »
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.

Re: MODULE: TWEEN 2! (2.0.1)
« Reply #8 on: 29 Jul 2015, 12:39 »
Thanks! :P
_______________________________________ ____________________

Cassiebsg

  • Cavefish
  • Fleeing the Cylon tyrrany...
Re: MODULE: TWEEN 2! (2.0.1)
« Reply #9 on: 29 Jul 2015, 19:07 »
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)
There are those who believe that life here began out there...

Edmundito

  • Mittens Serf
    • Best Innovation Award Winner 2014, for 'Tween Module'
    •  
    • I can help with scripting
    •  
  • Edmundito worked on a game that was nominated for an AGS Award!
Re: MODULE: TWEEN 2! (2.0.1)
« Reply #10 on: 10 Oct 2015, 22:04 »
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!)
« Last Edit: 12 Nov 2015, 19:20 by Edmundito »
Start using the Tween 2 Module!

Edmundito

  • Mittens Serf
    • Best Innovation Award Winner 2014, for 'Tween Module'
    •  
    • I can help with scripting
    •  
  • Edmundito worked on a game that was nominated for an AGS Award!
Re: MODULE: TWEEN 2! (2.0.1)
« Reply #11 on: 11 Oct 2015, 05:52 »
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:
Code: Adventure Game Studio
  1. int TweenSizeFromPivot(this GUI*, Pivot pivot, float timing, int toWidth, int toHeight, TweenEasingType easingType, TweenStyle style, float startDelay, TweenTimingType timingType) {
  2.   int toX = this.X;
  3.   int toY = this.Y;
  4.  
  5.   if (pivot == ePivotTopCenter || pivot == ePivotMiddleCenter || pivot == ePivotBottomCenter) {
  6.     toX += (this.Width - toWidth) / 2;
  7.   } else if (pivot == ePivotTopRight || pivot == ePivotMiddleRight || pivot == ePivotBottomRight) {
  8.     toX += (this.Width - toWidth);
  9.   }
  10.  
  11.   if (pivot == ePivotMiddleLeft || pivot == ePivotMiddleCenter || pivot == ePivotMiddleRight) {
  12.     toY += (this.Height - toHeight) / 2;
  13.   } else if (pivot == ePivotBottomLeft || pivot == ePivotBottomCenter || pivot == ePivotBottomRight) {
  14.     toY += (this.Height - toHeight);
  15.   }
  16.  
  17.   int sizeDuration = this.TweenSize(timing, toWidth, toHeight, easingType, eNoBlockTween, startDelay, timingType);
  18.   int positionDuration = this.TweenPosition(timing, toX, toY, easingType, eNoBlockTween, startDelay, timingType);
  19.   if (style == eBlockTween) {
  20.     WaitForLongest(sizeDuration, positionDuration);
  21.   }
  22. }

Add this to your Global Script Header or a Module Header:
Code: Adventure Game Studio
  1. enum Pivot {
  2.     ePivotTopLeft,
  3.     ePivotTopCenter,
  4.     ePivotTopRight,
  5.     ePivotMiddleLeft,
  6.     ePivotMiddleCenter,
  7.     ePivotMiddleRight,
  8.     ePivotBottomLeft,
  9.     ePivotBottomCenter,
  10.     ePivotBottomRight
  11. };
  12.  
  13. 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:
Code: Adventure Game Studio
  1. gIconbar.TweenSizeFromPivot(eBottomRight, 0.5, 160, 120);
« Last Edit: 11 Oct 2015, 06:18 by Edmundito »
Start using the Tween 2 Module!

Monsieur OUXX

  • Cavefish
  • Mittens Vassal
  • Mittens Half Initiate
    • I can help with proof reading
    •  
    • I can help with translating
    •  
    • I can help with voice acting
    •  
Re: MODULE: TWEEN 2! (2.0.1)
« Reply #12 on: 18 Dec 2015, 17:36 »
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
« Last Edit: 18 Dec 2015, 17:45 by Monsieur OUXX »
 

Monsieur OUXX

  • Cavefish
  • Mittens Vassal
  • Mittens Half Initiate
    • I can help with proof reading
    •  
    • I can help with translating
    •  
    • I can help with voice acting
    •  
Re: MODULE: TWEEN 2! (2.0.1)
« Reply #13 on: 18 Dec 2015, 18:03 »
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...
 

Edmundito

  • Mittens Serf
    • Best Innovation Award Winner 2014, for 'Tween Module'
    •  
    • I can help with scripting
    •  
  • Edmundito worked on a game that was nominated for an AGS Award!
Re: MODULE: TWEEN 2! (2.0.1)
« Reply #14 on: 19 Dec 2015, 03:57 »
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?
Start using the Tween 2 Module!

Monsieur OUXX

  • Cavefish
  • Mittens Vassal
  • Mittens Half Initiate
    • I can help with proof reading
    •  
    • I can help with translating
    •  
    • I can help with voice acting
    •  
Re: MODULE: TWEEN 2! (2.0.1)
« Reply #15 on: 19 Dec 2015, 12:12 »
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.

 

Re: MODULE: TWEEN 2! (2.0.2)
« Reply #16 on: 21 Apr 2016, 18:54 »
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? :/

Edmundito

  • Mittens Serf
    • Best Innovation Award Winner 2014, for 'Tween Module'
    •  
    • I can help with scripting
    •  
  • Edmundito worked on a game that was nominated for an AGS Award!
Re: MODULE: TWEEN 2! (2.0.2)
« Reply #17 on: 21 Apr 2016, 19:23 »
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.
Start using the Tween 2 Module!

Crimson Wizard

  • AGS Project Tracker Admins
    • Best Innovation Award Winner 2013, for spearheading the AGS 3.3.0 project
    •  
    • Lifetime Achievement Award Winner
    •  
Re: MODULE: TWEEN 2! (2.0.2)
« Reply #18 on: 21 Apr 2016, 20:15 »
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?
« Last Edit: 21 Apr 2016, 20:22 by Crimson Wizard »

Re: MODULE: TWEEN 2! (2.0.2)
« Reply #19 on: 21 Apr 2016, 22:49 »
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!