gpt4 book ai didi

actionscript-3 - AS3 Starling Framework Texture Atlas TypeError#1007

转载 作者:行者123 更新时间:2023-12-03 08:35:14 25 4
gpt4 key购买 nike

我是Starling框架的新手,目前正在学习如何使用它。

我已经使用starling框架从嵌入的PNG文件创建了纹理,该纹理可以正常工作并在屏幕上显示,但是我试图使Spritesheet(纹理图集)可以工作,并且这样做是给我的:

“错误#1007:尝试在非构造函数上实例化。”

从所有研究中,我已经完成了应该执行的代码。

这是我的Assets类中适用的代码。

public class Assets
{
[Embed(source="assets/sky.png")]
private static var SKY_CLASS:Class;
public static var SKY:Texture;

[embed(source="assets/generalsheet.png")]
private static var GENERAL_SHEET_CLASS:Class;
[embed(source="assets/generalsheet.xml", mimeType="application/octet-stream")]
private static var GENERAL_ATLAS_CLASS:Class;
public static var GENERAL_SHEET:TextureAtlas;

public static function init():void
{
SKY = Texture.fromBitmap(new SKY_CLASS());
GENERAL_SHEET = new TextureAtlas(Texture.fromBitmap(new GENERAL_SHEET_CLASS()), XML(new GENERAL_ATLAS_CLASS())); // this is where Flash Builder tells me there is an error
}

最佳答案

您只需要用大写的Embed标记,只需更改:

[embed(source="assets/generalsheet.png")]
private static var GENERAL_SHEET_CLASS:Class;
[embed(source="assets/generalsheet.xml", mimeType="application/octet-stream")]
private static var GENERAL_ATLAS_CLASS:Class;

至:
[Embed(source="assets/generalsheet.png")]
private static var GENERAL_SHEET_CLASS:Class;
[Embed(source="assets/generalsheet.xml", mimeType="application/octet-stream")]
private static var GENERAL_ATLAS_CLASS:Class;

另外,类名通常用 UpperCamelCase 编写,而 ALL_CAPITALIZED 保留用于常量。变量名通常用 lowerCamelCase lowercase_separated_by_underscore 编写。这是大多数ActionScript3(和Java)程序员所遵循的惯例,如果您坚持使用它,您的代码将更具可读性,因此下一次为您提供帮助会更容易;)

所以我建议:
[Embed(source="assets/sky.png")]
private static var SkyClass:Class;

public static var sky:Texture;

[Embed(source="assets/generalsheet.png")]
private static var GeneralSheetClass:Class;

[Embed(source="assets/generalsheet.xml", mimeType="application/octet-stream")]
private static var GeneralAtlasClass:Class;

public static var general_sheet;

public static function init():void
{
sky = Texture.fromBitmap(new SkyClass());

general_sheet = new TextureAtlas(Texture.fromBitmap(new GeneralSheetClass()), XML(new GeneralAtlasClass()));
}

关于actionscript-3 - AS3 Starling Framework Texture Atlas TypeError#1007,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11622329/

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