0

我想将 Spine 2d 嵌入到 Reactjs 应用程序中,当我阅读 Spine 文档时,他们提供从“@esotericsoftware/spine-player”导入脊椎;但我渲染应用程序它发出错误:尝试导入错误:'@esotericsoftware/spine-player'不包含默认导出(导入为'spine')。

我的代码:

import React from 'react';
import spine from '@esotericsoftware/spine-player';

const Character = () => {

    var jsonUrl = 'assets/Vi.json';
    var atlasUrl = 'assets/Vi.atlas';
    
    new spine.SpinePlayer('player-container', {
        jsonUrl: jsonUrl,
        atlasUrl: atlasUrl,
        animation: 'jump',
        premultipliedAlpha: true,
        backgroundColor: '#cccccc',
        viewport: {
            debugRender: true,
        },
        showControls: true,
    });

    return <div id="player-container"></div>;
};
4

1 回答 1

1

在我的情况下,我解决了这个问题。在spine-player 中没有名为spine 的导出成员。

import React from 'react';
import { SpinePlayer } from '@esotericsoftware/spine-player';
    
const Character = () => {

    var jsonUrl = 'assets/Vi.json';
    var atlasUrl = 'assets/Vi.atlas';
    
    new SpinePlayer('player-container', {
        jsonUrl: jsonUrl,
        atlasUrl: atlasUrl,
        animation: 'jump',
        premultipliedAlpha: true,
        backgroundColor: '#cccccc',
        viewport: {
            debugRender: true,
        },
        showControls: true,
    });

    return <div id="player-container"></div>;
};
于 2021-12-15T06:54:23.830 回答