简体   繁体   English

如何在Phaser3中添加Lottie Animation?

[英]How to add Lottie Animation in Phaser3?

I am trying to add Lottie animation in the Phaser 3 in my game. 我试图在我的游戏的Phaser 3中添加Lottie动画。

But I am not able to add. 但是我无法添加。 Here problem is, this animation I am attaching to the HTML DOM elements and so that the animation comes above the Phaser game canvas, Due to what I am not able to interact with my phaser game elements. 这里的问题是,我将此动画附加到HTML DOM元素上,因此该动画位于Phaser游戏画布上方,由于我无法与我的Phaser游戏元素进行交互。 I am not able to include the Lottie animation JSON file inside my Phaser game canvas. 我无法在Phaser游戏画布中包含Lottie动画JSON文件。

I have also tried to make container to be the canvas, but it is not working. 我也试图使容器成为画布,但是它不起作用。

Here is the example of the Lottie animation used in HTML5: Lottie animation Demo 这是HTML5中使用的Lottie动画的示例: Lottie animation Demo

This is the link to the Lottie animation file: Lottie animation JSON file example 这是Lottie动画文件的链接: Lottie动画JSON文件示例

Here is the code I am using for this, 这是我正在为此使用的代码,

 this.animation = bodymovin.loadAnimation({
      container: document.getElementById("game"), // Required
      path: "assets/json/RainLoop.json", // Required
      renderer: "canvas", // Required
      loop: true, // Optional
      autoplay: true, // Optional
      name: "Hello World", // Name for future reference. Optional.
    });

I want to include this Lottie animation to be include inside Phaser game canvas, but it is only including to my HTML DOM element. 我想将这个Lottie动画包含在Phaser游戏画布中,但仅包含在我的HTML DOM元素中。

It's possible there is not yet a supported way to load Lottie animations into a Phaser game canvas. 尚不存在将Lottie动画加载到Phaser游戏画布中的受支持方法。 Phaser can only display objects in the game canvas that are brought in with a loader, like this.load.sprite() , in the preload() method. Phaser只能在preload()方法中显示游戏画布中由加载程​​序带来的对象,例如this.load.sprite()

Unfortunately, it looks like the structure of Lottie json files doesn't match with the expected format -- [example] -- for the this.load.animation() loader. 不幸的是,对于this.load.animation()加载器,似乎Lottie json文件的结构与预期格式不匹配[示例]

You could attempt to parse the Lottie JSON file into the appropriate format, but that's probably going to be very complicated. 您可以尝试将Lottie JSON文件解析为适当的格式,但这可能会非常复杂。

If you want to use your Lottie animation as a background, you could set the Phaser canvas to transparent in the config object like this: 如果要使用Lottie动画作为背景,可以在config对象中将Phaser画布设置为透明,如下所示:

var config = {
  type: Phaser.AUTO,
  transparent: true,
  ...
};

And then you can load the Lottie animation into your HTML positioned appropriately with CSS to sit behind your canvas. 然后,您可以将Lottie动画加载到HTML中,并使用CSS适当地放置在画布后面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM