func_tween and func_easing
If you've used jQuery for simple animations, you know it's easy to make simple tweens look nice by using the variety of available easing options.
Whenever I try to do some nice effect in Graal, I end up writing the tweening code from scratch for that particular case, which is ridiculous. Tweening is pretty easy, but to make it look nice, you need some form of easing. Animations that start and stop abruptly look bad; it's usually better for there to be some kind of slow stop, fast start, or even bouncing :). I ported the wonderful jQuery easing plugin (BSD license) to GScript. I present to you: func_tween and func_easing. func_tween is just a couple functions that makes it easy to change the property of an object over time. You can use any object; images, GUIs, players, NPCs, etc. To use it, all you do is this: PHP Code:
You can use any easing available from the easing plugin, plus "linear" (normal, abrupt start and stop), and "swing" (the default, soft stop). You can see all of the available easings, and try them out, on this site (probably requires a non-ancient browser). Here's what they look like in game. The video is pretty choppy (sorry), but it looks very smooth in game. My favorite is probably at 1:38. Here's the two classes you'll need: func_tween PHP Code:
PHP Code:
|
Insta-Impressed. (Don't care about this not being a real word)
+rep Chris. |
+rep
very impressive |
One of the features of jQuery's animation lib is daisy-chaining animations.
item.animate().animate().animate(); Then they execute in that order. You can rig that up in GS2, should look into it. In my engine, tweening is part of the built-in scripting features. I accomplish daisy chaining by having the first call return an animation object, which is then built upon by the member functions of the animation object. That way, you can animate multiple variables concurrently and with some nice synactic sugar, too. |
Quote:
|
I edited my post with a way to implement it in GS2. Edit was supposed to be right after but I didn't have time, had to go off to school.
You should also rig a percentage of tweening to use as a variable, it's useful. For instance, in my implementation there's some preset types of easing, with each one being able to be modified by a scalar value. A value between -infinity and infinity. A value > 0 will make it start quickly, and end slowly. A value < 0 does the opposite, while a value of 0 will make it run at the same pace the entire time, with it all being relative to the distance from 0. Flash does the same thing. All it takes for that is a little multiplication against the value you input into the easing type function. |
This looks great. Good job.
|
Is there anything you can't do? +rep
|
I hate it, rep-
jk chris plz 4give |
3 Attachment(s)
http://forums.graalonline.com/forums...ad.php?t=79671 :confused:
Also with regards to chaining, I've been hanging on to this because I wanted to make it more extensible (like jQuery), but I've yet to devise an elegant solution. Anyway, you can check out the attachments. It includes some tweening functionality (specifically, linear and sinusiodal). Here's an example, the Zenkou message system. PHP Code:
|
Quote:
|
Hey Chris, I've been using this to tween the x & y of GUI controls successfully a few times, but it doesn't seem to like tweening the width/height of them at all. The GUI control disappears, and reappears with the target width/height on the last frame.
Is it your code not supporting it or is it just another beautiful day in GScript? :p If there's anything you could on your end to "fix" it, I'd much appreciate it :) |
Quote:
|
Quote:
|
Try tweening another variable and then setting the height/width to that variable.
|
All times are GMT +2. The time now is 01:19 PM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.