Jump to content
Search Community

Is there a way to use clearProps or an equivalent to reset PixiJS sprite transforms/tweens?

Slowchange test
Moderator Tag

Go to solution Solved by Rodrigo,

Recommended Posts

Hey everyone! Can anyone tell me, is there a way to use clearProps or an equivalent to reset PixiJS sprite transforms/tweens (with or without PixiPlugin?)


I'm wanting to reset some transforms on some sprites for a scene that can be exited and re-entered within my web app - as I understand it, clearProps is a CSSPlugin method/property, so not sure if it is valid or accessible through PixiPlugin. I'd rather not destroy the actual sprite instances themselves, just to do with the way I'm loading and managing my 'master' pool of sprites at app level.


I tried a couple of approaches: 

gsap.set(sprite, {pixi: {clearProps: true}})

gsap.set(sprite, {clearProps: true})

and received this message both times

Invalid property clearProps set to true Missing plugin? gsap.registerPlugin()


Sorry for no CodePen, I didn't think this warranted one but can whip one up if it makes my question more answerable!



Link to comment
Share on other sites

It's pretty tough to troubleshoot without a minimal demo - the issue could be caused by CSS, markup, a third party library, your browser, an external script that's totally unrelated to GSAP, etc. Would you please provide a very simple CodePen or CodeSandbox that demonstrates the issue? 


Please don't include your whole project. Just some colored <div> elements and the GSAP code is best (avoid frameworks if possible). See if you can recreate the issue with as few dependancies as possible. If not, incrementally add code bit by bit until it breaks. Usually people solve their own issues during this process! If not, then at least we have a reduced test case which greatly increases your chances of getting a relevant answer.


Here's a starter CodePen that loads all the plugins. Just click "fork" at the bottom right and make your minimal demo

See the Pen aYYOdN by GreenSock (@GreenSock) on CodePen


If you're using something like React/Next/Vue/Nuxt or some other framework, you may find StackBlitz easier to use. We have a series of collections with different templates for you to get started on these different frameworks: React/Next/Vue/Nuxt.


Once we see an isolated demo, we'll do our best to jump in and help with your GSAP-specific questions. 

Link to comment
Share on other sites

No problem, sorry, should've just done one in the first place. You'll see what I'm talking about in the demo below, hopefully. Trying to clearProps on a PIXI sprite doesn't work, presumably because the sprite is not a DOM element. Just wondering if there's an equivalent way to do this (clearProps/reset transforms) for the sprite.


See the Pen jOvNMOM by stuartmack (@stuartmack) on CodePen

Link to comment
Share on other sites

  • Solution



As far as I can tell the clear props is not working in the case of PIXI display object. Is worth noticing that clear props will remove all the applied styles and set the element back to it's previous state before the animation, with that in mind you could achieve the same result using the revert method:



Here is a fork of your codepen:

See the Pen OJoLwWB by GreenSock (@GreenSock) on CodePen


Hopefully this clear things up. Let us know if you have more questions.

Happy Tweening!

  • Like 2
Link to comment
Share on other sites

9 hours ago, Rodrigo said:

Is worth noticing that clear props will remove all the applied styles and set the element back to it's previous state before the animation

That isn't entirely accurate - clearProps is indeed just for CSS properties and it is solely for clearing them which has nothing to do with returning them to the previous state before the animation. For example, if the "x" was 100 before the animation started and you clearProps, it's not as if it returns it to 100. 


The revert() method, on the other hand, does return individual properties that the tween affects back to the pre-animation state. 


You could just set the properties back to 0: 

See the Pen eYLOqwK?editors=1010 by GreenSock (@GreenSock) on CodePen

  • Like 1
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...