Jump to content
Search Community

jpg animation into a canvas

dinchu test
Moderator Tag

Go to solution Solved by GreenSock,

Recommended Posts

I have been struggling in creating animations of jpg's in a canvas using GSAP. the only thing i was needing to achieve is a simple animation fadein fadeout of 2 images creating a transition. it works super good an easy outside a canvas. I think with older versions of the library this was possible but not anymore. the fact the new methods: to(), fromTo() take as first parameter a dom element limit the possibility of calculating the animation frame by frame in a canvas.

I couldn't find a single example in the docs with a case like mine.

The reason why i insist in the use of canvas is the capabilities of a canvas to export a stream of video

Link to comment
Share on other sites

Without a minimal demo, it's very difficult to troubleshoot; the issue could be caused by CSS, markup, a third party library, a 3rd party script, etc. Would you please provide a very simple CodePen or Stackblitz that illustrates the issue? 

 

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

 

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

that loads all the plugins. Just click "fork" at the bottom right and make your minimal demo

 

Using a framework/library like React, Vue, Next, etc.? 

CodePen isn't always ideal for these tools, so here are some Stackblitz starter templates that you can fork and import the gsap-trial NPM package for using any of the bonus plugins: 

 

Please share the StackBlitz link directly to the file in question (where you've put the GSAP code) so we don't need to hunt through all the files. 

 

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 need to get the values of the opacity in the onUpdate function to pass them to the elements drawed in the canvas. but i don't know how to doit and instead of a smooth transition you just see images going from opacity 0 to 1 without steps every 2 secs (because of the timeouts) 

See the Pen yLrJGOQ by Pablo-Delgado-the-typescripter (@Pablo-Delgado-the-typescripter) on CodePen

Link to comment
Share on other sites

hi @dinchu you can separate the clear and the draw of the canvas inside a ticker func since now you are handling them inside the tween,

here is one example with canvas to see the clearing, drawing, and animation of the stars

 

See the Pen yLryMwK by ahmed-attia (@ahmed-attia) on CodePen

 

and another one with pixi 

https://stackblitz.com/edit/vitejs-vite-7ycqfl?file=main.js&terminal=dev

  • Like 2
Link to comment
Share on other sites

  • Solution

Just to clarify, GSAP is more capable than it has ever been - there was never a time when GSAP just automatically handled <canvas> draw operations for you. It can animate literally any property of any object (not just DOM elements), so you could do it this way: 

 

See the Pen OJGXKwZ?editors=0010 by GreenSock (@GreenSock) on CodePen

 

Enjoy!

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