2

我开发了一个 Flex/Starling 游戏,我想使用 Atlas Texture 来优化所有精灵调用。我的问题是我使用了一个清晰简单的代码,具有基本的资源并且我无法运行,我得到一个参数错误,纹理不能为空。我知道 .getTexture 方法什么也没找到,但我看不出如何解决这个问题,我的代码:

[Embed(source = "Atlas_bg/AtlasBackground.xml")]
public var AtlasXml:Class

[Embed(source = "Atlas_bg/AtlasBackground.png")]
public var AtlasPng:Class


// create atlas
var texture:Texture = Texture.fromBitmap(new AtlasPng());
var xml:XML = XML(new AtlasXml());
var atlas:TextureAtlas = new TextureAtlas(texture, xml);
// display a sub-texture
var objsTexture:Texture = atlas.getTexture("star_0");// ne trouve rien
var objsImage:Image = new Image(objsTexture);
addChildAt(objsImage, 0.6);
objsImage.x = 200;
objsImage.y = 200;

XML 内容:

<TextureAtlas imagePath="AtlasBackground.png">
    <SubTexture name="star_0" x="2" y="2" width="20" height="20"/>
    <SubTexture name="star_1" x="2" y="24" width="20" height="20"/>
</TextureAtlas>

谢谢。

4

2 回答 2

4

我认为您没有正确嵌入Atlas XML 文件,因此无法正确读取TextureAtlas的信息。

尝试以下两个添加:

  1. 在您的元标记中添加mimeType属性Embed

    [嵌入(source = "Atlas_bg/AtlasBackground.xml", mimeType="application/octet-stream")] public var AtlasXml:Class;

  2. 在 XML 文件的开头添加以下行:

    <?xml 版本="1.0" 编码="UTF-8"?>

在此之后,清理您的项目几次以摆脱先前使用不正确的嵌入文件的构建并再次构建您的项目。现在一切都应该正常了。

于 2012-11-09T14:58:43.363 回答
0

你确定那是指的地方ArgumentError吗?我注意到您在第二个参数中使用aNumber而不是a 函数。intaddChildAt()

试着把它换成这个,看看是否能解决问题:

addChild(objsImage);
于 2012-11-09T02:00:48.067 回答