Cordova App 中的 Phaser 3:如何在 iOS 版本中正确使用图像

问题描述

我在 Cordova 应用程序中使用 Phaser 3。 我正在尝试在屏幕上显示图像。 该代码在浏览器版本中正常工作。 因此,如果我运行:cordova run browser 然后一切正常显示

但是如果我运行 cordova run ios

然后图像无法正确显示。 我也使用 Xcode 打开了该应用程序,但没有看到任何相关错误

以下是相关部分:

function preload ()
{
    console.log('preload.......')
    this.load.image("emptytile","./assets/sprites/emptytile.png");
    // this.load.image("logo","url(../img/logo.png)");
    this.load.image("logo","./assets/sprites/logo.png");
}

function create ()
{


    this.add.image(200,200,"emptytile");   
    this.add.image(30,100,"logo"); 
    
    const ThirtyConsonantsButton = this.add.text(100,'Thirty Consonants',{ fill: '#0f0' })
    ThirtyConsonantsButton.setInteractive();

    ThirtyConsonantsButton.on('pointerdown',() => { console.log('pointerdown'); });

  
}

然后为了查看任何可能的错误,我通过 Xcode 打开应用程序,控制台调试区域显示以下内容

2021-03-25 19:25:01.049522+0800 HelloCordova[23044:1549947] Apache Cordova native platform version 6.2.0 is starting.
2021-03-25 19:25:01.049690+0800 HelloCordova[23044:1549947] Multi-tasking -> Device: YES,App: YES
2021-03-25 19:25:01.058846+0800 HelloCordova[23044:1549947] Could not load the "LaunchStoryboard" image referenced from a nib in the bundle with identifier "io.cordova.hellocordova"
2021-03-25 19:25:01.291165+0800 HelloCordova[23044:1549947] The preference key "AllowNewWindows" is not defined and will default to "FALSE"
2021-03-25 19:25:01.292422+0800 HelloCordova[23044:1549947] The preference key "mediaplaybackAllowsAirPlay" is not defined and will default to "TRUE"
2021-03-25 19:25:01.297305+0800 HelloCordova[23044:1549947] The preference key "AllowBackForwardNavigationGestures" is not defined and will default to "FALSE"
2021-03-25 19:25:01.297452+0800 HelloCordova[23044:1549947] The preference key "Allow3DTouchLinkPreview" is not defined and will default to "TRUE"
2021-03-25 19:25:01.297533+0800 HelloCordova[23044:1549947] CDVWebViewEngine will reload WKWebView if required on resume
2021-03-25 19:25:01.297660+0800 HelloCordova[23044:1549947] Using WKWebView
2021-03-25 19:25:01.298095+0800 HelloCordova[23044:1549947] [CDVTimer][console] 0.048995ms
2021-03-25 19:25:01.298296+0800 HelloCordova[23044:1549947] [CDVTimer][handleopenurl] 0.058055ms
2021-03-25 19:25:01.299815+0800 HelloCordova[23044:1549947] [CDVTimer][intentandnavigationfilter] 1.384974ms
2021-03-25 19:25:01.300050+0800 HelloCordova[23044:1549947] [CDVTimer][gesturehandler] 0.066042ms
2021-03-25 19:25:01.300178+0800 HelloCordova[23044:1549947] [CDVTimer][TotalPluginStartup] 2.219081ms
2021-03-25 19:25:01.442929+0800 HelloCordova[23044:1549947] WF: === Starting WebFilter logging for process HelloCordova
2021-03-25 19:25:01.443112+0800 HelloCordova[23044:1549947] WF: _userSettingsForUser : (null)
2021-03-25 19:25:01.443229+0800 HelloCordova[23044:1549947] WF: _WebFilterIsActive returning: NO
2021-03-25 19:25:02.073818+0800 HelloCordova[23044:1549947] The preference key "AutoHideSplashScreen" is not defined and will default to "TRUE"
2021-03-25 19:25:02.884798+0800 HelloCordova[23044:1549947] Running cordova-ios@6.2.0
2021-03-25 19:25:02.885008+0800 HelloCordova[23044:1549947]      Phaser v3.53.1 (WebGL | Web Audio)  https://phaser.io
2021-03-25 19:25:02.885198+0800 HelloCordova[23044:1549947] resizeGame
2021-03-25 19:25:02.970339+0800 HelloCordova[23044:1549947] preload.......

enter image description here

解决方法

这篇文章给出了答案:

Cordova iOS Cross origin requests are only supported for HTTP

cordova plugin add https://github.com/AraHovakimyan/cordova-plugin-wkwebviewxhrfix

希望这能在未来帮助其他人......