Jump to content
Search Community

Animation nested circles with PIXI.js

Milovan test
Moderator Tag

Recommended Posts

Hello guys i couldn't make the animation as i wanted, so i need your help!

I want to expand and shrink a circle from 7 radius to 140 radius (radius is a PIXI parameter for circles width) . with duration of 2 seconds. i want the circle to get animated while expanding, and reset to 7, without being animated. The timeline should repeat 2 times, on the last repeat the animation should end, when the circle reaches 140 radius! 

This is what i came up with so far, but the circle ends up with random radius  when the animation ends :) 
 

const outerCircle = new Graphics();
 
const color = "rgba(119, 207, 240, 0.3)";
let coordinates = 300;
let radiusInner = 7;
 
outerCircle.beginFill(color).drawCircle(coordinates, coordinates, radiusInner);
 
const timelineInner = gsap.timeline({
  repeat: 1,
});
 
timelineInner.to(innerCircle, {
  duration: 2,
  onUpdate: () => {
    if (radiusInner < 140) {
      radiusInner += 2;
    } else {
      radiusInner = 7;
    }
 
    innerCircle.clear();
    innerCircle
      .beginFill(color)
      .drawCircle(coordinates, coordinates, radiusInner);
  },
});
 
timelineInner.play();
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 Stackblitz 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

I assume you meant to do something more like this: 

let circle = {radiusInner: 7};
gsap.to(circle, {
	radiusInner: 140,
	duration: 2,
	repeat: 1,
	onUpdate: () => {
		innerCircle.clear();
		innerCircle
			.beginFill(color)
			.drawCircle(coordinates, coordinates, circle.radiusInner);
	},
});

Just use a proxy object and animate whatever property you want.

Link to comment
Share on other sites

Hi,

 

Since you mentioned PIXI and seems from the small snippet you posted that you're trying to use it, PIXI is actually more convenient for these type of situations, since you don't have to clear the canvas object, since PIXI returns a display object that you can manipulate as you want, PIXI handles all the complex stuff behind the scenes for you.

 

Is worth mentioning that radius is not a property of a circle/arc/ellipse graphic object. In this cases you have to either tween the height/width or the scale on each axis (scaleX/scaleY using the PIXI Plugin) in order to set the new radius of the circle.

 

This is a super simple example using GSAP and the PIXI Plugin:

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

 

Hopefully this helps.

Happy Tweening!

  • 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...