Я просматривал различные ресурсы по этой теме, и мне кажется, что мне нужен загрузчик для каждого Sprite, который содержит файл изображения (png).
Я пытаюсь создать систему рендеринга тайлов, и создал сетку X спрайтами Y, но все они на самом деле ссылаются на один и тот же файл изображения.
Есть ли другой способ сделать это? (Сделать спрайт общим файлом данных png)
Пример кода того, что я сделал.
// Create an array of X * Y Loaders
var cTileLoaders:Array = new Array( 100 ); // for example 10 by 10 grid
var cTiles:Array = new Array( 100 );
var nIndex:int = 0;
var nImgLoadCount:int = 0;
for ( ; 100 > nIndex; ++nIndex ) {
cTileLoaders[ nIndex ] = new Loader();
cTiles[ nIndex ] = new Sprite();
// perform more sprite initialization
....
cTileLoaders[ nIndex ].contentLoaderInfo.addEventListener( Event.COMPLETE, ImageLoaded
cTileLoaders[ nIndex ].Load( new URLRequest( "some image path" ) );
}
// handler for image loaded
function ImageLoaded( eEvent:Event ):void {
++nImgLoadCount;
// when all 100 sprite data are loaded
// assuming there is no i/o error
if ( 100 == nImgLoadCount ) {
cTiles[ nIndex ].addChild( cTileLoaders[ nIndex ].content );
}
}