airbnb / lottie-web

Render After Effects animations natively on Web, Android and iOS, and React Native. http://airbnb.io/lottie/
MIT License
30.5k stars 2.87k forks source link

How to load multiple animation in on canvas at the specific point with specific size #2607

Open UsmanShafaqat opened 3 years ago

UsmanShafaqat commented 3 years ago

i am using lottie in react js and i am facing issue for playing a animation at the specific point please help me in this

lottie.loadAnimation({ animationData: animationData, renderer: 'canvas', autoplay: true, loop: true, isSubframeEnabled: true,

        rendererSettings: {
            context: ctx,
            scaleMode: 'noScale',
            clearCanvas: true,
            preserveAspectRatio: 'xMinYMin meet',
            progressiveLoad: true,
        }
    })
bodymovin commented 3 years ago

hi, can you share more data on what the problem is?

UsmanShafaqat commented 3 years ago

i have multiple animations and i want all to play all of them in one canvas at a specific x y position how can i do it using lottie

voytekhodaniil commented 3 years ago

I have same question. I want draw lottie at specific position of canvas (Like ctx.drawImage(image, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight) )

voytekhodaniil commented 3 years ago

Anyway I can propose this workaround

constructor(pos, data) {
    this.pos = pos
    const container = document.createElement('div')
    document.body.appendChild(container);
    this.lottie = Lottie.loadAnimation({
        animationData: data,
        loop: true,
        autoplay: true,
        renderer: "canvas",
        rendererSettings: {
            scaleMode: 'noScale'
        },
        container
    });
    this.img = container.querySelector("canvas");
    container.remove();
}
draw(ctx) {
    ctx.drawImage(this.img, this.pos.x, this.pos.y)
}
UsmanShafaqat commented 3 years ago

@bodymovin i am waiting for your answer..

bodymovin commented 3 years ago

if you control the canvas, you can execute your transforms on the canvas and then delegate control to lottie so it performs the drawing.

UsmanShafaqat commented 3 years ago

any code example please..

UsmanShafaqat commented 3 years ago

@bodymovin please help me out in this i need little code explanation how can i play multi animation in one canvas at diff axis. thanks in advance

renatodolza commented 2 years ago

@bodymovin please help me out in this i need little code explanation how can i play multi animation in one canvas at diff axis. thanks in advance

@bodymovin help us

bodymovin commented 2 years ago

@renatodolza can you share an example of where you are stuck?

renatodolza commented 2 years ago

I have at least 30 animations, see below an example with 3 animations simultaneously, being able to increase more depending on the need image

I'm using it in SVG, I would like to do it in CANVAS