Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,812
Reaction score
887
First Language
German
Primarily Uses
RMMZ
Description

Allows animation of every numeric attribute on any object.

Videos

I'm currently working on some scripts to use this.

Prerequisites

(optional) "Iavra Weak Reference" (http://forums.rpgmakerweb.com/index.php?/topic/40868-iavra-weak-reference/) - only if Weak References are used.

How to Use

Place this script below every class that you want to support animating.

Call one of the following methods to start an animation:

IAVRA::ANIMATE.start(<object>, <attributes>, <duration>, <easing>, <delay>, <chain>) <callback><object>.iavra_animate_start(<attributes>, <duration>, <easing>, <delay>, <chain>) <callback># Parameters:# <object>: Object to animate# <attributes>: Attributes, as a hash like {<name> => <target value>}# <duration>: Animation duration, in frames. Defaults to 1.# <easing>: Easing function to use. Defaults to :linear.# <delay>: Delay before starting the animation, in frames. Defaults to 0.# <chain>: If true, the animation will be queued and wait for older ones to finished first. Defaults to false.# <callback>: An optional block to be execute, after the animation finished. "self" refers to the object.# ExampleIAVRA::ANIMATE.start(<object>, {:attr => 100}, 120, :linear, 60, true) {p self}The example will wait 60 frames, before animating the attribute :attr of <object> from its current value to 100 over the duration of 120 frames using linear easing.If :attr is already animating, the animation will be queued and wait for older ones to finish, first.

After the animation completes, the supplied block is called and prints the object to the console.

Most parameters have defaults, so you usually won't need to specify everything.

WARNING: Since the animation data is stored inside the object and procs can't be serialized, make sure to only define a callback if the object either isn't included in the savefile or if you are sure, that the game won't be saved while the animation is running.

To interact with animating objects, the following methods can be used:

# Stops the animation for the specified attributes on the target. If no attributes are specified, stops all animations.IAVRA::ANIMATE.stop(<object>, *attrs)<object>.iavra_animate_stop(*attrs)# Skips the current animation for the selected attribute and advances the queue.IAVRA::ANIMATE.skip(<object>, *attrs)<object>.iavra_animate_skip(*attrs)# Returns the frame of the current animation for the selected attribute. Returns nil if the attribute isn't animating and 0 if the animation is delayed.IAVRA::ANIMATE.step(<object>, attr)<object>.iavra_animate_step(attr)# Returns true, if the object has any active, non-delayed animations.IAVRA::ANIMATE.animating?(<object>)<object>.iavra_animate_animating?All easing functions except :linear are contained in their own library script, so they can be swapped out for your own functions. The position of the library doesn't matter.Configuration

To enable animating for a class (and all of its subclasses), you have to register it first, like this:

CLASSES = { Game_Picture => [ lambda {|a| instance_variable_get:)"@#{a}")}, lambda {|a, v| instance_variable_set:)"@#{a}", v)} ]}Make sure to be as specific as possible (for example, registering your own Windows instead of Window_Base), to avoid unintended side effects.You can alter the default values of some parameters like this:

# Default chaining behaviour. If set to true, all animations will be queued unless you define "false" when starting the animation.DEFAULT_CHAINING = false# Default easing function to use, if none is specified when starting the animation.DEFAULT_EASING = :linearYou can decide to use weak references to animated objects instead of referencing them directly. This adds a dependency to "Iavra Weak Reference":
Code:
WEAK_REFERENCES = false
Terms of UseFree to use for both commercial and non-commercial games. Please give credit.

Credits

Iavra

FAQ

None so far

Changelog

(For changes done prior to release, look into the script)

- 1.00: Release version

- 1.01: Added the "step" method, that was previously removed. It returns the current frame of the active animation for an attribute. Returns 0 for delayed animations and nil if the attribute isn't animating.

- 1.02: Moved the update_animation method to occur before the normal update, since the old version sometimes resulted in strange behaviour.

- 1.03: Added dependency to "Iavra Weak Reference". Objects are now updated from outside and don't need their own update method anymore. They still have their own animation data, though, since checking equality with WeakRefs can be a nightmare.

- 1.04: Added a new configuration option to toggle between Weak and Strong references. "Iavra Weak Reference" is only needed if Weak References are used.

Special Thanks

- Robert Penner (http://robertpenner.com/easing/): For creating the easing functions.

- Exhydra: For testing and reporting a lot of early bugs.

Download

Script: http://pastebin.com/1MgCVWPe

Library: http://pastebin.com/vExVACp5
 
Last edited by a moderator:

Sixth

Veteran
Veteran
Joined
Jul 4, 2014
Messages
2,201
Reaction score
853
First Language
Hungarian
Primarily Uses
RMVXA
This sounds interesting...


Do you plan to release a demo with some working examples? I would like to take a look at real examples in action.


Or maybe a video of showing off some things which could be done with this... But I would prefer the demo. :D


Pretty please? *-*


Also, can it show multiple animations at once (on the same object or on different ones), or only one at a time? I suppose it can, but who knows. :p


If it can, this would be an ideal tool for creating menu animations for moving windows, zooming window, rotating windows, etc.


But damn if I know what those methods do in the library (more like how they do what they do), lol. I got a head-ache when trying to figure it out, math hurts. >.>
 

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,812
Reaction score
887
First Language
German
Primarily Uses
RMMZ
I will make a video or demo, but that will probably take some time as i'm pretty busy.

Animations are executed on a per-attribute base, so if you do:

<object>.iavra_animate_start({:x => 100}, 20, :linear).iavra_animate_start({:y => 20}, 50, :bounce_in)both attributes will animate independently from each other and have their own queues for chaining (this is also the case, if you start both animations in the same command).Regarding the methods, i advise to take a look at this: http://easings.net/

"easeInOutElastic" is the only one i'm missing currently, since the implementation i've found seemed to be kinda buggy.

/edit: Regarding chaining: Remember that, when you animate Game_Picture objects, that they don't get destroyed during a "Erase Picture" command. So if you have queued animations and erase the picture, those animations will still be running in the background. So, it might be a good idea to call "stop" on an animated picture before you erase it to be on the safe side.
 
Last edited by a moderator:

Ossra

Formerly Exhydra
Veteran
Joined
Aug 21, 2013
Messages
1,076
Reaction score
867
First Language
English
Primarily Uses
RMMV
Nice work! I'll poke around a bit more, but so far everything works wonderfully.
 

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,812
Reaction score
887
First Language
German
Primarily Uses
RMMZ
Objects no longer update themselves, but are managed from outside. This means that they no longer need their own "update" method.


Since this means i have to keep references to the animated objects, i added an optional dependency to "Iavra Weak Reference" (linked in OP) and a new configuration option, WEAK_REFERENCES.


For more information about what that script does, please refer to its own thread.


If you only intend to animate sprites and windows and dispose them correctly (what you should do anyway), there is no need to use weak references.
 
Last edited by a moderator:

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,512
Reaction score
11,998
First Language
English
Primarily Uses
RMVXA
As suggested in the other thread, here is my query.

What I want to do:

Fade out the player sprite smoothly to zero opacity over 22 frames.  A little later, bring the opacity back up to 255 instantly.  

The fade out doesn't really work smoothly using the change opacity command in set move route.

I've looked at the script, and honestly I haven't a clue what I'm supposed to do.  It also says that I might need the script for weak references.  I have no idea if I need it or not.

It could simply be that using this sort of script is way outside my league.  It wouldn't be the first.
 

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,812
Reaction score
887
First Language
German
Primarily Uses
RMMZ
First step is registering your class. In this case i would go for Game_Character instead of Game_Player. The attribute "opacity" only got a defined getter (attr_reader), so you have 2 options:

1) Add an additional setter to the Game_Character class and use the "send" attribute access.

2) Use the "instance_variable_get/set" access to directly modify the attribute.

Here i used the second option, which is easier, but also would bypass any corrections done by existing getters/setters (there are none):

CLASSES = { Game_Character => [ lambda {|a| instance_variable_get:)"@#{a}")}, lambda {|a, v| instance_variable_set:)"@#{a}", v)} ]}Then call the script like this:
Code:
IAVRA::ANIMATE.start($game_player, {:opacity => 0}, 22)    # fade out
For the fade in you could call the script with ":opacity => 255" and "1" (1 is default, so you can actually omit the second parameter), but that would be way too oversized for setting a simple value, so do it like this:
Code:
IAVRA::ANIMATE.stop($game_player)                          # maybe not needed, stops the animation above if it's still running.$game_player.instance_variable_set(:@opacity, 255)
I don't think you need weak references. The full reasons why:- A weak reference allows access to an object without preventing the garbage collector from cleaning it.

- You usually only need them when you forget to dispose your sprites (what you should do anyway) or do long-running animations on objects that only exist in a particular scene.

- $game_player (which you would be animating) exists in every scene, so it won't be garbage collected, anyway.

- Even if you were animating the sprite directly (which i wouldn't do), it gets disposed by Spriteset_Map, anyway, which will cause all animations on it to stop.

/edit: The method call above uses the standard easing, which is :linear by default. You won't even need the Library script for that, but you can include it if you want to experiment a bit with different functions (elastic/bounce functions allow for some "flicker" effect, for example).
 
Last edited by a moderator:

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,512
Reaction score
11,998
First Language
English
Primarily Uses
RMVXA
That works beautifully.  Thank you for your help.
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,512
Reaction score
11,998
First Language
English
Primarily Uses
RMVXA
I'm still stumbling on script calls.  The script header gives this as the example:

IAVRA::ANIMATE.start(<object>, {:attr => 100}, 120, :linear, 60, false) { p self }

I have no problem when the <object> is an event.  I can do the call either from the event itself or trigger it from another event.  What I can't work out is the script call for a picture, because i do not see how to specify which picture it is going to be.  For example

I enter a map. Bit of dialogue.  I then want a picture to gradually fade in. I use the 'Show Picture', specifying which one etc.  Let us assume that I specified a picture and set the opacity at 0 when I first entered the map.  I now want it to fade in - but I can't work out how to indicate the picture in the script call.

Could you tell me how to do that, please.

Thanks
 

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,812
Reaction score
887
First Language
German
Primarily Uses
RMMZ
You can get pictures like this:

$game_map.screen.pictures[<id>]Game_Picture gets registered in the script just like Game_Character (it's actually one of the examples given in the script).Also note that the Game_Picture instances are always the same, even if you load a new picture. So if the picture is animating and you display a new one, the animation will continue. So make sure to call "stop" on the picture beforehand.
 
Last edited by a moderator:

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,512
Reaction score
11,998
First Language
English
Primarily Uses
RMVXA
I'm still not getting this right.  I have this script call

IAVRA::ANIMATE.start($game_map.screen.pictures[1], {:opacity => 250}, 30)

but I get the error message target doesn't support animating.

What have I done wrong?
 

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,812
Reaction score
887
First Language
German
Primarily Uses
RMMZ
That error gets thrown, when the class isn't registered in your configuration.

Your CLASSES should at least look like this:

Code:
CLASSES = {	Game_Picture => [		lambda {|a|    instance_variable_get(:"@#{a}")}, 		lambda {|a, v| instance_variable_set(:"@#{a}", v)}	],	Game_Character => [		lambda {|a|    instance_variable_get(:"@#{a}")}, 		lambda {|a, v| instance_variable_set(:"@#{a}", v)}	]}
I edited the default configuration to support characters, pictures and sprites. This should do for the most common cases.
 
Last edited by a moderator:

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,512
Reaction score
11,998
First Language
English
Primarily Uses
RMVXA
That's what I've got.  This is what my configuration looks like - except the spacing looks different in the script editor than it does in this pasted version.

Code:
CLASSES = {			Game_Picture => [				lambda {|a|    instance_variable_get(:"@#{a}")}, 				lambda {|a, v| instance_variable_set(:"@#{a}", v)}			], 			Sprite_Base => [				lambda {|a|    send(:"#{a}")}, 				lambda {|a, v| send(:"#{a}=", v)}			]		}		CLASSES = {	    Game_Character => [	   	lambda {|a|    instance_variable_get(:"@#{a}")}, 	  	lambda {|a, v| instance_variable_set(:"@#{a}", v)}    	]    }
 
Last edited by a moderator:

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,812
Reaction score
887
First Language
German
Primarily Uses
RMMZ
That looks pretty strange, to say the least ^^


You can copy the now updated configuration from Pastebin, if you like. I just tested it for pictures and it works.


/edit: In your example the second CLASSES overwrites the first one. Actually, i'm kinda surprised, that that even works, since it's a constant.
 
Last edited by a moderator:
  • Like
Reactions: Kes

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,512
Reaction score
11,998
First Language
English
Primarily Uses
RMVXA
It worked fine for character and sprite, don't know why either, if it overwrites.

Anyway, I put in your updated version and picture now works exactly how I want it to, so once again, thank you very much.
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,512
Reaction score
11,998
First Language
English
Primarily Uses
RMVXA
Back again with another query.  It may be that it's not possible to do what I'm trying to achieve, but this is what I would like to do.

To have a battle skill animation play on an event on the map.  However, for greater dramatic effect, I want to make this 23 frame animation last 60 frames.  It's quite a complex one, so to redo it in the animations tab in the data base to triple its length is something I'd like to avoid.  Here is what I have so far:

IAVRA::ANIMATE.start($game_map.events(3), {:animation_219}, 60)

However, this throws the error message

unexpected '}', expecting tASSOC

Is that because it can't play animation #219 over 60 frames, or because I've done something else stupid?

Thanks.
 

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,812
Reaction score
887
First Language
German
Primarily Uses
RMMZ
Regarding your question: This is not something the script can do (well, maybe it can by manipulating the @ani... attributes of Sprite_Base, but that just seems wrong).

Regarding the error: Your hash is incomplete. It should be like

{:animation_219 => <some value>}However, this will try to modify an attribute called "animation_219" which will either throw an error, because it doesn't exist, or sets an attribute which does nothing on its own./edit: Also, events are stored as a hash, so you would access them like this:

Code:
$game_map.events[3]     # not (3)
 
Last edited by a moderator:

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,512
Reaction score
11,998
First Language
English
Primarily Uses
RMVXA
Thanks for the info, and the clarifications regarding the formula.  I thought it was unlikely to be possible, but "hope springs eternal..."
 

Dhaundre

Villager
Member
Joined
Jul 4, 2015
Messages
18
Reaction score
0
First Language
Spanish
Primarily Uses
Hi There :)

I'd like to animate a black screen to fade in and out over an ongoing text box so it should look like the text is fading in and out.

I have a lot of scripts in my game but this one seems advanced and I really don't know how to install it. 

I've placed it under Game_Picture but the game crashes inmediately. 

Any noob friendly guide or demo? The "class" thing is  :o

Thanks and sorry for he noobism xD
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,512
Reaction score
11,998
First Language
English
Primarily Uses
RMVXA
All custom scripts, without exception go under Materials and above Main.  Putting it where you did will cause the game to crash.  

As you want a picture, set up the Class thing to look like this

#========================================================================== CLASSES = { Game_Picture => [ lambda {|a| instance_variable_get:)"@#{a}")}, lambda {|a, v| instance_variable_set:)"@#{a}", v)} ], Game_Character => [ lambda {|a| instance_variable_get:)"@#{a}")}, lambda {|a, v| instance_variable_set:)"@#{a}", v)} ], Sprite_Base => [ lambda {|a| send:)"#{a}")}, lambda {|a, v| send:)"#{a}=", v)} ] }[EDIT - I'm not sure why this is showing the indentation like this - in the script editor the word Classes lines up with the # at the beginning of line 112]

Have your 'show picture' command, with the picture's opacity set to zero.

You then do a script call which will look something like this:

IAVRA::ANIMATE.start($game_map.screen.pictures[1], {:opacity => 255}, 100)

That 100 is the number of frames that you want it to take to go from zero to full opacity.

Then you have your text showing followed by another script call to reverse the opacity, so something like this

IAVRA::ANIMATE.start($game_map.screen.pictures[1], {:opacity => 0}, 100)

Again the 100 is whatever number of frames you want this to take.
 
Last edited by a moderator:

Latest Threads

Latest Profile Posts

Tiamat-86 wrote on ATT_Turan's profile.
apparently since its turning 15 years old this year the ps3 is considered "retro". now how old do you feel?
guess that means im an "antique" gamer since ill still play games as old as i am.
"you know your getting old when your childhood console changes ethnicity" lol it turned yellow
I'm making Toilet in Wonderland 2. and tell vinny about it lol
WE ARE THE BORG. YOUR BIOLOGICAL AND TECHNOLOGICAL DISTINCTIVENESS WILL BE ADDED TO OUR OWN. RESISTANCE IS FUTILE.
D2R save files are so broken. how was the beta test better then the full release. blizzard's last hope crashed and burned.
they're getting no more chances from me.

Forum statistics

Threads
115,337
Messages
1,089,129
Members
150,013
Latest member
keda27
Top