游戏资产不在Kongregate中加载 [英] Game assets not loading in Kongregate

查看:159
本文介绍了游戏资产不在Kongregate中加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚创建了我的第一个游戏,并且遇到了一些问题。我上传到Kongregate(但尚未发布),并在预览外部文件(音乐和三张图片)不加载。游戏的其余部分工作正常。



如果我尝试更改它,以便在其中包含资源的zip并更改代码中的目录,则会崩溃。

我使用的是FlashDevelop,所以一切都是程序化的。我注意到swf只有几kb大,所以是否有资产编译到swf文件并加载它们,还是我需要做别的?



请帮忙,并提前致谢。

解决方案

好吧,让我解释一下。让我们假设您的主模块 game.swf 从同一个文件夹加载一些图片 asset.jpg 。你在本地测试它,它工作得很好。您在您的网站上放置 game.html game.swf asset.jpg http://niamke.com/ ,它仍然有效。然后,您将游戏发布为 http://kongregate.com/games/niamke/myniamkegame/它突然停止加载 asset.jpg



为什么



通过浏览器处理来自Flash Player的HTTP请求。所以浏览器从Flash Plugin实例中获取 asset.jpg 的请求。在一个页面内可以有来自多个不同域的各种内容(包括多个Flash应用程序),所以浏览器不用费心去找出正确的地址,并且明显地试图加载相对于最上面的HTML文档,基本上 http://kongregate.com/games/niamke/myniamkegame/asset.jpg 这是不存在。



如何避免它

的代码可以为您加载的文件指定正确的URL。只要您的内容附加到Stage,任何展示对象都可以访问包含绝对SWF网址的loaderInfo对象。

  Files.parseURL(loaderInfo.url); 

var aLoader:Loader = new Loader;
var aRequest:URLRequest = new URLRequest(Files.baseUrl +asset.jpg);

Loader.load(aRequest);

执行

 
{
公共类文件
{
//长期比尔盖茨和Windows和反斜杠。
静态公共函数figureSlash(value:String):String
{
var aSplit:Array = value.split(/);
var oSplit:Array = value.split(\\);

return(aSplit.length> = oSplit.length)? /:\\;
}

static public baseUrl:String;
static public var systemSlash:String;

//假设为了
//处理相关的资源文件,正确解析SWF url。
static public parseURL(value:String):void
{
//图正确的斜线。
systemSlash = figureSlash(value);

//将SWF URL拆分为数组并删除SWF名称。
var aSplit:Array = value.split(systemSlash);
aSplit [aSplit.length - 1] =;

//获取SWF根文件夹。
baseUrl = aSplit.join(systemSlash);
}
}
}


I just created my first game, and am having some problems. I uploaded to Kongregate(but didn't publish yet), and in the preview the external files(music and three pictures) don't load. The rest of the game works fine.

If I try to change it so there is a zip with the assets in it and change the directory in the code, it falls apart.

I'm using FlashDevelop, so everything is programatic. I noticed the swf is only a few kb large, so is there anyway to compile the assets into the swf file and load them that way, or do I need to do something else?

Please help, and thanks in advance.

解决方案

Ok, let me explain then. Lets assume you have your main module game.swf that loads some image asset.jpg from the same folder. You test it locally, it works just fine. You put game.html, game.swf and asset.jpg on your site http://niamke.com/ and it still works. Then you publish your game as http://kongregate.com/games/niamke/myniamkegame/ and it suddenly stops loading asset.jpg.

Why

HTTP requests from Flash Player are handled via browser. So the browser gets a request for "asset.jpg" from Flash Plugin instance. There could be all kinds of content (including several Flash Apps) from several different domains within one page, so browser does not bother to figure the correct address out, and plainly tries to load in relatively to the topmost HTML document, basically http://kongregate.com/games/niamke/myniamkegame/asset.jpg which is not there.

How to avoid it

You should create a small piece of code that figures the correct URLs for the files you load. As soon as your content attached to Stage, any display object can access the loaderInfo object which contains the absolute SWF URL.

Usage

Files.parseURL(loaderInfo.url);

var aLoader:Loader = new Loader;
var aRequest:URLRequest = new URLRequest(Files.baseUrl + "asset.jpg");

Loader.load(aRequest);

Implementation

package
{
    public class Files
    {
        // Long live Bill Gates and Windows and backslashes.
        static public function figureSlash(value:String):String
        {
            var aSplit:Array = value.split("/");
            var oSplit:Array = value.split("\\");

            return (aSplit.length >= oSplit.length)? "/": "\\";
        }

        static public var baseUrl:String;
        static public var systemSlash:String;

        // Supposed to dissect the SWF url in order to
        // process relative resource file urls properly.
        static public function parseURL(value:String):void
        {
            // Figure correct slash.
            systemSlash = figureSlash(value);

            // Split SWF URL into Array and remove SWF name.
            var aSplit:Array = value.split(systemSlash);
            aSplit[aSplit.length - 1] = "";

            // Obtain the SWF root folder.
            baseUrl = aSplit.join(systemSlash);
        }
    }   
}

这篇关于游戏资产不在Kongregate中加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆