简体   繁体   English

从移相器中的其他服务器加载图像资产

[英]load images assets from other server in phaser

I am trying to load an image from the report server but it did not showing up when i add it into sprite by this. 我正在尝试从报表服务器加载图像,但是当我将其添加到sprite中时却没有显示。

preload: function () {
    game.load.baseURL = 'http://somthing.com/';
    game.load.crossOrigin = 'anonymous';
},
create: function () {
    var data = new Image();
    data.src = sessionStorage.getItem("game_icon0");
    game.load.image('newIcon','game_icon0',data);
    game.add.sprite(0, 0, 'newIcon');
},

When i try to load it into game it did not show up there. 当我尝试将其加载到游戏中时,它并未显示在此处。 please help 请帮忙

First, while it may work as-is, best practices state you should move your asset loading into the preload function. 首先,虽然它可以按原样运行,但最佳实践表明您应该将资产加载移到预加载功能中。 This ensures that they're available before they're used. 这样可以确保在使用之前可以使用它们。

The next issue is loading the image remotely. 下一个问题是远程加载图像。 If the session item already has the URL of the item I would think you should be able to load it directly. 如果会话项目已经具有该项目的URL,我认为您应该可以直接加载它。

preload: function () {
    game.load.baseURL = 'http://somthing.com/';
    game.load.crossOrigin = 'anonymous';
    game.load.image('newIcon',sessionStorage.getItem("game_icon0"));
},

create: function () {
    game.add.sprite(0, 0, 'newIcon');
},

It might make sense to handle the grabbing of information from the session in some other way, such as setting variables or creating an object, depending upon how many API calls you need to make. 以某种其他方式(例如,设置变量或创建对象)来处理从会话中获取信息的方法可能很有意义,具体取决于您需要进行多少次API调用。

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

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