0

我正在用 haxe/openfl 制作游戏引擎。到目前为止,它只是应该显示属于事物对象的图像。到目前为止,我构建的内容在部署为 Flash 应用程序时可以完美运行,但在我将其部署为 Windows 应用程序时会立即关闭。它只是在 html5 中创建一个空白屏幕。我没有测试过其他目标。我正在使用 HIDE,每次崩溃时,HIDE 都会显示消息:“文件 c:\Users\Adu\Documents\HaxeProjects\Downloaded\Export\windows\cpp\bin\Downloaded.exe 已更改。重新加载?” 并给我选择是或否。我的回答似乎并没有改变这种情况。当我手动进入导出目录并运行应用程序时,它给出了错误:“错误自定义([file_write,stderr])。这是我的代码:

主要的:

package;
import openfl.display.Graphics;

import openfl.Assets;
import openfl.display.Bitmap;
import openfl.display.Sprite;
import openfl.events.Event;
import openfl.Lib;
import openfl.text.TextField;
import openfl.text.TextFormat;
import openfl.ui.Keyboard;
import openfl.events.*;

class Main
{

    static var obj(default,default):ObjectManager; //contains the list that all gameobjects add themselves to
    static var stage = Lib.current.stage;

    public static function main() // this is the gameloop
        {
            // static entry point
            startUp();
            var running = true; // gives me a way to exit the gameloop
            while (running)
                {
                    logic();
                    render();
                    Lib.current.stage.addEventListener(KeyboardEvent.KEY_DOWN, function(event)
                                {
                                    if (event.keyCode == Keyboard.ESCAPE)
                                        {
                                            running=false;
                                        }
                                });
                }
        }

    static function startUp() // runs once, when the game is started
        {
            obj= new ObjectManager();
            stage.align = openfl.display.StageAlign.TOP_LEFT;
            stage.scaleMode = openfl.display.StageScaleMode.NO_SCALE;
        }           


    static function logic() // loops, this handles the logic
        {
            var thing = new GameObject("assets/pixel_thing.png", 1, obj);

            var mech = new GameObject("assets/mechwarrior.png", 0, obj);
        }

    static function render() // runs right after logic and draws everything to the screen
        {
            for (i in obj.objects) //iterates through a list of gabeobjects and draws them, it is 2 dimensional so that I can draw objects in blocks
                {
                    for (j in i)
                        {
                            Lib.current.addChild(j);
                        }

                }


        }   


}

游戏对象:

package ;
import openfl.display.BitmapData;
import openfl.Assets;
import openfl.display.Bitmap;
import openfl.display.Sprite;
import openfl.events.Event;
import openfl.Lib;
import openfl.text.TextField;
import openfl.text.TextFormat;

class GameObject extends Sprite
{
public function new(?image:String, zOrder:Int, objectManager:ObjectManager) // image is the image, zorder is which layer it's drawn on, lower layers are drawn on top objectmanager is just there to help me pass the list to the object
{
    super();

    var data = Assets.getBitmapData(image);//this is the image data
    var bitmap:Bitmap = new Bitmap(data);//this is the actual image
    Lib.current.stage.addChild(bitmap);//this sraws the image when the object is instantiated
    objectManager.objects[zOrder].push(this);// this adds it to the list of objects
}
}

对象管理器:

package ;


class ObjectManager
{
public var objects = new Array<Array<GameObject>>();
}

为什么它适用于flash而不适用于windows?我该如何解决?

4

1 回答 1

1

首先 - 这在闪存上也不能正常工作。您是在 Flash 调试播放器中运行它吗?如果你不这样做,我认为是这种情况,你不会看到任何例外。

此行有一个空引用错误:

objectManager.objects[zOrder].push(this);// this adds it to the list of objects

您正在访问 index 处的数组,该数组zOrder不存在。objects正在初始化为[],其中不包括“内部数组”(它不能,真的,它怎么知道应该有多少?)。


现在,默认情况下,Windows 版本不会为您提供非常有用的调试信息。一个简单的解决方法是使用 neko(它的行为与 hxcpp 构建的大部分行为相同,除了它编译得更快并且性能更差)进行调试,默认情况下您会在崩溃时获得堆栈跟踪。

果然,这和flash中的问题是一样的,唯一的区别是native构建崩溃,而flash只是“忽略它”并试图继续。

Invalid field access : objects
Called from GameObject::new line 92
Called from GameObject::$init line 83
Called from Main::logic line 61
Called from Main::main line 38
Called from Reflect::callMethod line 58
Called from ApplicationMain::main line 91
Called from openfl.Lib::create line 113

要获得更好的 hxcpp 构建调试信息,您可能需要查看crashdumper库。

于 2014-08-12T09:42:26.670 回答