2012-11-08 49 views
2

我开发了一个Flex/Starling游戏,我希望使用Atlas Texture来优化所有的sprite调用。 我的问题是,我使用一个清晰​​和简单的代码,与基本资源,我不能运行,我得到一个参数错误,纹理不能为空。 据我所知,.getTexture方法发现什么,但我没有看到如何解决这个问题,我的代码:Starling,Atlas纹理“纹理不能为空”

[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> 

THX。

回答

0

您确定这是ArgumentError指向的地方吗?我注意到你正在使用Number而不是int作为第二个参数中的addChildAt()函数。

尝试交换到这一点,看看是否能解决的事情:

addChild(objsImage); 
+0

是的,这很奇怪(可能是一个错字),但它不是错误的来源。 addChildAt需要一个int参数,以便传递给它的数字被截断为其整数部分(在本例中为0),它应该可以工作。 – danii

4

我想你是不是嵌入阿特拉斯XML文件正确,因此TextureAtlas不能正确的信息读。

试试下面这两个加法:

  1. 添加mime类型属性,在Embed元标记:

    [嵌入(来源= “Atlas_bg/AtlasBackground.xml”,mime类型=“应用/ octet-stream“)] public var AtlasXml:Class;

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

    < XML版本= “1.0” 编码= “UTF-8”? >

在此之后,清理项目几次摆脱以前的作品有不正确的嵌入式文件并重新生成项目。一切都应该现在工作。

+0

Thx,我会尝试你的提示,并且我会尽快告诉你是否解决了问题! – Georgio