gpt4 book ai didi

package - 导入类时找不到类异常 : Haxe (With OpenFL + Flixel libraries)

转载 作者:行者123 更新时间:2023-12-01 23:49:07 25 4
gpt4 key购买 nike

我最近开始摆弄 HaxeFlixel,在尝试制作一个真正简单的游戏时,我遇到了这个错误:

source/PlayState.hx:10: characters 7-16 : Class not found : GameLogic

这不是我第一次涉足编程游戏或任何东西,但我不知道为什么会弹出此错误。对于初学者来说,GameLogic 甚至不是一个类,它是一个包。当我尝试从我的 GameLogic 包中导入我的基本 Player 类时出现错误。

我的基本播放器类:

 package GameLogic;

import flixel.FlxSprite;
import flixel.util.FlxColor;

class Player extends FlxSprite {

public function new(X:Float=0, Y:Float=0) {
super(X, Y);
makeGraphic(32, 32, FlxColor.WHITE);
}

}

抛出异常的地方:

     import GameLogic.Player;

class PlayState extends FlxState{

private var p:Player;

override public function create():Void{
p = new Player(20, 20);
add(p);
super.create();
}

我的[相关]目录结构:

  | src
| | GameLogic
| | | Player.hx
| | PlayState.hx

最佳答案

作为Haxe docs状态:

Each part of the path in package names must begin with a lower case letter and, like all types, type names in packages must begin with an upper case letter. Hence My.Pack is an invalid package, as is my.Pack. Similarly, my.pack.e would not be a valid type name or import

您必须使用小写的 G 命名您的程序包 gameLogic 才能被识别为正确的程序包名称。 up-to-date docs中的相关部分读起来稍微复杂一些,但本质上对于这个问题的意思是一样的:

Define: Module

All Haxe code is organized in modules, which are addressed using paths. In essence, each .hx file represents a module which may contain several types. A type may be private, in which case only its containing module can access it.

The distinction of a module and its containing type of the same name is blurry by design. In fact, addressing haxe.ds.StringMap can be considered shorthand for haxe.ds.StringMap.StringMap. The latter version consists of four parts:

  1. the package haxe.ds
  2. the module name StringMap
  3. the type name StringMap
  4. the type parameter Int

概述了名称解析算法 here更详细。

关于package - 导入类时找不到类异常 : Haxe (With OpenFL + Flixel libraries),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27471026/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com