ody Posted December 19, 2019 Share Posted December 19, 2019 Hello, I want to know how to manage "ticker" in GSAP3. the previous version was well documented... but with "gsap.ticker" we lost the whole parameters except "callback:function". So can we have an example of how to migrate previous code to the new architecture? Best Regard! Link to comment Share on other sites More sharing options...
OSUblake Posted December 19, 2019 Share Posted December 19, 2019 All of that is kind of pointless when you can use bind. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind var onTick = myCallback.bind(myScope, "param1", "param2"); gsap.ticker.add(onTick); ... gsap.ticker.remove(onTick); 3 2 Link to comment Share on other sites More sharing options...
OSUblake Posted December 19, 2019 Share Posted December 19, 2019 9 minutes ago, ody said: I want to know how to manage "ticker" in GSAP3. Forgot to say this. There's just add and remove. Straight from the source code. add(callback) { _listeners.indexOf(callback) < 0 && _listeners.push(callback); _wake(); }, remove(callback) { let i; ~(i = _listeners.indexOf(callback)) && _listeners.splice(i, 1); }, 3 Link to comment Share on other sites More sharing options...
youwh Posted April 15, 2020 Share Posted April 15, 2020 i'm using bind, but I can't remove the function. Comparing the basic example and the bind method i use, the function name in the listener is different. for example.. myFunction() name is "myFunction" in the listener list, but the bind method check2() name is "bound check2"? I'm not sure if just removing the object from the listeners would be the same as using gsap.ticker.remove Link to comment Share on other sites More sharing options...
OSUblake Posted April 15, 2020 Share Posted April 15, 2020 What does your code look like? If you do it just like this, you shouldn't have any problems. var onTick = myCallback.bind(myScope, "param1", "param2"); gsap.ticker.add(onTick); ... gsap.ticker.remove(onTick); Link to comment Share on other sites More sharing options...
youwh Posted April 15, 2020 Share Posted April 15, 2020 init():void{ gsap.ticker.add(this.check2.bind(this, body)); } protected check2($body): void { if ($body.x === 0 && $body.y === 0) { gsap.ticker.remove(this.check2); } } basically like this. if using without the bind method, it could work, but it doesn't looks pretty next time if i need to override it Link to comment Share on other sites More sharing options...
youwh Posted April 15, 2020 Share Posted April 15, 2020 23 minutes ago, OSUblake said: What does your code look like? If you do it just like this, you shouldn't have any problems. var onTick = myCallback.bind(myScope, "param1", "param2"); gsap.ticker.add(onTick); ... gsap.ticker.remove(onTick); this work, though will need to have it as an var rather than targeting the function directly. Link to comment Share on other sites More sharing options...
OSUblake Posted April 15, 2020 Share Posted April 15, 2020 When you do bind inline like that, you don't have a reference to the new function, so you can't remove it. That's just how it works, and isn't related to gsap. So you either need store the bound function. init():void{ this.boundCheck2 = this.check2.bind(this, body) gsap.ticker.add(this.boundCheck2); } protected check2($body): void { if ($body.x === 0 && $body.y === 0) { gsap.ticker.remove(this.boundCheck2); } } Or use a class field arrow function. check2 = () => { if (body.x === 0 && body.y === 0) { gsap.ticker.remove(this.check2); } } init():void{ gsap.ticker.add(this.check2); } 3 1 Link to comment Share on other sites More sharing options...
youwh Posted April 15, 2020 Share Posted April 15, 2020 ahh, make sense. thanks for the quick solution. now i guess have to check back some of the bind I used to see if it really does what it intends to or not... 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now