Animation > Custom Easing / Transition

450 views
Skip to first unread message

David King

unread,
Oct 27, 2013, 5:41:42 AM10/27/13
to game-clos...@googlegroups.com
I've just read the following thread (from February), it says that custom easing requires modification of core C++ files;


Does this still apply?

In my tinkerings I've found sdk/timestep/animate/transitions.js which has following definitions:

exports.linear = function (n) { return n; }
exports.easeIn = function (n) { return n * n; }
exports.easeInOut = function (n) { return (n *= 2) < 1 ? 0.5 * n * n * n : 0.5 * ((n -= 2) * n * n + 2); }
exports.easeOut = function (n) { return n * (2 - n); }

So I've tried using my own lambda function and it works in the simulator:

animate(sprite).now({ scale: 1, y: (y-2) }, 200, function (n) { return n; });

Would this also function as expected when running natively?

David King

unread,
Oct 28, 2013, 7:28:25 AM10/28/13
to game-clos...@googlegroups.com
I've ported over the jQuery / Robert Penner easing functions to accept a single parameter in keeping with the existing transition code. I've made changes to the javascript timestep files but not the C++ ones yet *. They work very nicely on the simulator.

After checking through the github repos I'm unable to locate the sources for these. The devkit repo has a .gitignore for the sdk folder and it doesn't appear to be a submodule... so I've created a gist for the time being:
If a developer wouldn't mind giving me some tips on contributing, I've already signed the CLA

Original easing equations:
The easing functions are as follows:
  • linear
  • easeInQuad - has alias "easeIn" for backward compatibility
  • easeOutQuad - has alias "easeOut" for backward compatibility
  • easeInOutQuad
  • easeInCubic
  • easeOutCubic
  • easeInOutCubic - has alias "easeInOut" for backward compatibility
  • easeInQuart
  • easeOutQuart
  • easeInOutQuart
  • easeInQuint
  • easeOutQuint
  • easeInOutQuint
  • easeInSine
  • easeOutSine
  • easeInOutSine
  • easeInExpo
  • easeOutExpo
  • easeInOutExpo
  • easeInCirc
  • easeOutCirc
  • easeInOutCirc
  • easeInElastic
  • easeOutElastic
  • easeInOutElastic
  • easeInBack
  • easeOutBack
  • easeInOutBack
  • easeInBounce
  • easeOutBounce
  • easeInOutBounce
For visual reference


* I'll have to learn a little C++ before I attempt that, but TBH most of the transitions are basic Math...

Martin Hunt

unread,
Oct 29, 2013, 5:43:59 PM10/29/13
to David King, game-clos...@googlegroups.com
Hi David,

The files you're looking for are in the timestep submodule located at ./lib/timestep/.  Everything in ./sdk/ is a symlink, designed to expose only the public portions of various libraries to the client.  If you're in a terminal, you can probably see where these symlinks point to by running "ls -l" from inside the SDK directory.  You can also view all submodules by running "git submodule" from the base folder of your devkit installation.

You should create a pull request for https://github.com/gameclosure/timestep with your changes, and we'll take a look and merge them in!

Thanks for contributing!
Martin

Martin Hunt

unread,
Oct 29, 2013, 5:49:50 PM10/29/13
to game-clos...@googlegroups.com, David King
Also, for native code, you'll want to look at the following files:


Each transition is defined as an element in an enum in the header file, and the implementations are defined as macros.

David King

unread,
Oct 30, 2013, 5:07:12 AM10/30/13
to game-clos...@googlegroups.com, David King
Cheers Martin,

I'd tinkered with git submodule while simultaneously reading github, had myself tied up in knots!

I've got everything I need from your reply; I shall be looking at that today on my lunch break :-)

David King

unread,
Oct 30, 2013, 6:20:26 AM10/30/13
to game-clos...@googlegroups.com, David King
Right then, I've ported my javascript transitions into a C++ test-rig and got each working as expected

All that's left is to convert them from C++ Functions into C++ Macros - which appears to be a different kettle of fish altogether! It's cool though; I'll figure it out in due course.

I am right in thinking that these must be Macros? From what I've read there's a world of difference, but I'm too naive with C++ to understand how or why...

David King

unread,
Oct 30, 2013, 1:26:13 PM10/30/13
to game-clos...@googlegroups.com, David King
After speaking to a colleague about Functions and Macros he said that the code as I'd written it served the same purpose and was good to go.

Thusly, I have sent the pull request.

Once we get this merged in I'll update the docs and write a (personal) blog article
Reply all
Reply to author
Forward
0 new messages