gsap, revert animation after play - gsap

I'd like to play an animation with gsap, but after it has finished playing, I want to reset it. Like after playing that animation, reset, after it is finished. Without clicking anywhere or calculating the play time, sleeping or waiting the process. Just simply something like:
TweenLite.to(thing, 1, {x:'-20px'}).reset();
(ideally, there is no reset call in gsap.. how to acieve this?)
I can't get it to work with .seek(), .time(), .pause().
Those always interrupt the animation.
Preferable I want to use a simple TweenLite, or if it has to, a TimelineLite.
Im searching / looking for it since hours..

There are many ways to do it, but here's a simple one:
TweenLite.to(thing, 1, {x:-20, onComplete:function() {
this.pause(0); //seeks the tween (this) to 0 (playhead's starting position) and pauses immediately.
}});
Does that help?

Related

How to stop MPAndroidChart chart.centerViewToAnimated( currentXVisible + 60, currentY, YAxis.AxisDependency.LEFT, 15000 );

I am wanting to animate my drawn data, with controls much like a media player: Play, Stop, fast forward, etc....over my Xaxis - AKA over time....
I have tried creating my own Runnable both on and off the UI thread with no success with making calls to increment the xvalue by small amounts, etc .... but does not move the view port windows.
I can get my chart to animate using chart.centerViewToAnimated, but want to be able to "stop" this animation ... I cannot see how to do this even with a ViewPortHandler...
Any ideas??
It looks like the animation started by chart.centerViewToAnimated(...) cannot be cancelled. So you need to make small steps. If the steps are small enough, you can use chart.centerViewTo(...) (without animation).
I have implemented this with 50ms interval and it looks decent.

Sound effect delayed after first time it's played

I am using the SoundJS library within the CreateJS suite. I use the LoadQueue class to preload all my sounds. I am finding that when I go to play a sound effect for the first time it's delayed by a good half second before it plays. After the first play, it will play perfectly after that.
The problem also re-occurrs if you don't play any sounds for a minute or so. Then playing a sound effect will have that delay on first play.
Any idea why? Is there a work around to fix the issue? (ie. playing background music at 0% volume.
Here is my code (using typescript) :
import ReelStop from "../sound/reelstop.mp3";
private queue = new createjs.LoadQueue();
this.queue.installPlugin(createjs.Sound);
this.queue.on("complete", this.handleComplete, this);
this.queue.addEventListener("progress", this.onProgress);
this.queue.loadManifest([
// other sounds and images
{id: "reelStop", src: ReelStop},
]);
// after the preload complete has fired, the first time the sound is played there is that 500ms+ delay :
const reelStop= createjs.Sound.play("reelStop");
reelStop.volume = 0.5;
Thanks in advance for any ideas you may have

Using NSProgessIndicator as playback bar

I am currently writing a music playing program for OS X. I am implementing an NSProgessIndicator to show the current playback progress of a song as it plays. How can I efficiently update the progress once per second without getting off-sync with the music?
Ideally I want something like iTunes has where it also has numbers to show the exact playback time and time remaining:
Currently the only thing I can think of is to use an NSTimer with the interval set 1 second and force it run on the main thread through that. However, this seems very inefficient and also like it might not keep perfect sync. Is there a better way to go about this?
You can use the timer just to update the info, in this case the audio current time. AVAudioPlayer has a property with the same name currentTime which will return the time for you as NSTimeInterval(seconds).

How to hear sound from mpmovieplayer at a specific time using UISlider?

I'm working on an iOS movie editor project. For this editor, i use MPMoviePlayer to show the video file selected by the user.
I use custom controls, and I have a UISlider that enables the user to move the player's currentTime position. When the user touches the slider, movie is paused and its currentTime changes along with the UISlider's value.
Everything works perfectly, but now i need to let the user hear the sound at this currentTime position.
For those who know iMovie, when you move your mouse over a movie event, you see the image and hear the sound at this position, and that's what i'd like in my editor.
I've tried to call player's play method with à NSTimer to stop after 0.2 seconds, but the result is kind of messy.
Has anyone already achieved to do something like this ?
Thanks !
Best regards.
Seeking takes time; that's why you've ended up using a timer. The real problem here is that MPMoviePlayerController, while convenient because it gives you controls, is a blunt instrument; it's just a massive simplified convenience built on top of AVFoundation. But you don't need the built-in controls, so I would suggest throwing away your entire implementation and getting down to the real stuff, using AVFoundation instead (AVPlayer etc). Now you have a coherent way to seek and get a notification when the seek has completed (seekToTime:completionHandler:), so you'll be able to start playing as soon as possible. Plus, AVFoundation is the level where you'll be doing all your "editing" anyway.

Libgdx - How to spawn particles only when I hold mouse button?

So I slowly got to know how to manipulate particle system and emitter in-game through the code, but there is one simple task I can't get to know how... How can I spawn particles ONLY when I hold the mouse button? I tried a work-around by setting the maxCount of emmiter to 0 when its not pressed but then it either doesnt emit particles at all, or just makes the existing ones disappear immidiately, which looks very unnatural and I don't want it. Is there a way to emit them "manually" in render method?
You probably want to do set the Emission scaled value on the particle emitter. You can leave the max count at whatever maximum particle number you want.
To turn off the creation of particles:
emitter.getEmission().setLow(0);
emitter.getEmission().setHigh(0);
To turn it back on:
emitter.getEmission().setLow(10);
emitter.getEmission().setHigh(10);
Try using a Pool combined with your listeners:
gitHub link
Ok this is what I got to make it work. "blowing" is basically a boolean that is true when holding mouse button and false when not.
if (blowing) {
effectEmitter.start();
} else {
effectEmitter.allowCompletion();
}