[未处理的承诺拒绝:TypeError:_expoPixi.PIXI.application不是函数

问题描述 投票:0回答:1

错误:[未处理的承诺被拒绝:TypeError:_expoPixi.PIXI.application不是函数。 (在'_expoPixi.PIXI.application({] ....

我试图在react-native expo项目上使用pixi js。

这是package.json文件。

"dependencies": {
    "@expo/vector-icons": "^9.0.0",
    "expo": "^33.0.7",
    "expo-asset-utils": "^1.1.1",
    "expo-gl": "~5.0.1",
    "expo-pixi": "^1.0.1",
    "expokit": "^32.0.3",
    "lodash": "^4.17.11",
    "native-base": "^2.10.0",
    "prop-types": "^15.6.2",
    "react": "16.8.3",
    "react-dom": "^16.8.6",
    "react-native": "https://github.com/expo/react-native/archive/sdk-33.0.0.tar.gz",
    "react-native-gesture-handler": "^1.0.9",
    "react-native-svg": "^9.11.1",
    "react-native-web": "^0.11.2",
    "react-navigation": "^3.0.9",
    "react-navigation-redux-helpers": "^2.0.9",
    "react-redux": "^6.0.0",
    "react-style-proptype": "^3.2.2",
    "redux": "^4.0.1",
    "redux-thunk": "^2.3.0"
  },
  "devDependencies": {
    "babel-preset-expo": "^5.0.0",
    "expo-cli": "^2.10.1",
    "eslint": "^5.16.0",
    "eslint-config-universe": "^1.0.7",
    "prettier": "^1.17.0"
  },
  "resolutions": {
    "expo-pixi/@expo/browser-polyfill": "0.0.1-alpha.3"
  },
  "private": true

和app.json文件。

...

"privacy": "unlisted",
    "sdkVersion": "33.0.0",
    "platforms": [
      "ios",
      "android"
    ],
    "version": "1.0.0",
    "orientation": "portrait",
    "icon": "./src/assets/images/icon.png",
    "splash": {
      "image": "./src/assets/images/splash.png",
      "resizeMode": "cover",
      "backgroundColor": "#222222"
    },
    "updates": {
      "fallbackToCacheTimeout": 0
    },
    "assetBundlePatterns": [
      "**/*"
    ],
    "ios": {
      "supportsTablet": true
    }

...

这是我的屏幕代码。

import React from 'react';
import { GLView } from 'expo-gl';
import {PIXI} from 'expo-pixi';

export default class GameReady extends React.Component {
  render() {
    return (
      <GLView
        style={{ flex: 1 }}
        onContextCreate={async context => {
          const app = PIXI.application({
            context,
            backgroundColor: 0xffffff,
          });

          const sprite = await PIXI.spriteAsync(
            'https://ubisafe.org/images/sans-transparent-8-bit.png'
          );

          app.stage.addChild(sprite);

          sprite.anchor.set(0.5);

          sprite.x = app.screen.width / 2;
          sprite.y = app.screen.height / 2;

          app.ticker.add(() => (sprite.rotation += 0.01));
        }}
      />
    );
  }
}

错误:


[Unhandled promise rejection: TypeError: _expoPixi.PIXI.application is not a function. (In '_expoPixi.PIXI.application({]

Stack trace:
  src\containers\Game\GameReady.js:11:39 in _callee$
  node_modules\regenerator-runtime\runtime.js:45:44 in tryCatch
  node_modules\regenerator-runtime\runtime.js:271:30 in invoke
  node_modules\regenerator-runtime\runtime.js:45:44 in tryCatch
  node_modules\regenerator-runtime\runtime.js:135:28 in invoke
  node_modules\regenerator-runtime\runtime.js:170:17 in <unknown>
  node_modules\promise\setimmediate\core.js:45:7 in tryCallTwo
  node_modules\promise\setimmediate\core.js:200:23 in doResolve
  node_modules\promise\setimmediate\core.js:66:12 in Promise
  node_modules\regenerator-runtime\runtime.js:169:27 in callInvokeWithMethodAndArg
  node_modules\regenerator-runtime\runtime.js:192:38 in enqueue
  node_modules\regenerator-runtime\runtime.js:216:8 in async
  src\containers\Game\GameReady.js:10:25 in _callee
  node_modules\expo-gl\build\GLView.js:26:43 in _onSurfaceCreate
  node_modules\react-native\Libraries\Renderer\oss\ReactNativeRenderer-dev.js:93:15 in invokeGuardedCallbackImpl

我在博览会开始时就运行了这个项目。但是我得到了上述错误。如何解决此问题?帮我。谢谢。

react-native expo pixi.js
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.