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