_LAB_
Content Type
Profiles
Forums
Store
Blog
Product
Showcase
FAQ
Downloads
Posts posted by _LAB_
-
-
Hi everyone, I've got a very specific use case where I'd like to extend the timeline for my team's convenience (and for code clarity).
We are using Phaser 2 and would like to "add sounds" to the gsap timeline. That is we create a tween with the sound's duration and add that to the timeline.
I had achieved this by creating an effect aptly namedaddSound
and extending the timeline for the effect so it's nice and convenient for us to use. It all works flawlessly if we use sound objects as the target (see the example below)gsap.timeline() .addSound(someSoundObject) .to(someFancySprite, { y: 100, duration: 0.5, ease: 'none'} )
However sometimes we use sound keys as strings instead of objects. (see code snippet below)
gsap.timeline() .addSound('someSoundKey') .to(someFancySprite, { y: 100, duration: 0.5, ease: 'none'} )
Now the effect will see the string and search the cache for any sound objects matching that key and use that instead.
Problem is that whenever we use strings as the target, GSAP will assume that is a DOM element. No problem, so I examine the source code and discover that thetoArray
method has a mysterious parameter calledleaveStrings
. Currently there's no way we can utilise that flag so that it will not use thedocument.querySelectorAll
method.
So my question is, is it possible to use theleaveStrings
flag at all just for the effect I'm using so that it will know that any strings as the target is NOT a DOM element?
I'd like to use strings purely for convenience so that the team will have flexibility of using objects OR strings when using the effect. In the past we did use convenience functions that would return a tween (something like the code snippet below) but compared to using theaddSound
effect it seems clunky.gsap.timeline() .add(createSoundTween('somekey')) .to(someFancySprite, { y: 100, duration: 0.5, ease: 'none'})
Register Effects
in GSAP
Posted
Thanks for taking the time to reply with your suggestions @Rodrigo & Jack, I think hijacking the prototype is the way to go since that is what happens when you add a new effect.
I did think of the prototype method but wasn't sure I was getting the right reference to get it all working. I'll give
gsap.core.Timeline.prototype
a go and hope that is the right prototype reference.Finally, thanks for creating such an amazing tweening library, over the years it has become such an indispensable tool for us to use.