I am using dynamic loading for sprites (Sirisian’s TextureManager) …
I load when I start the game so I think I will need some loading screen and force people to wait… but I am wondering if it’s better to load one large file or many files.
ie, does the number of files matter when cumulative(?) image size will stay the same?
thanks.
[quote=misterooga;2334480]I am using dynamic loading for sprites (Sirisian’s TextureManager) …
I load when I start the game so I think I will need some loading screen and force people to wait… but I am wondering if it’s better to load one large file or many files.
ie, does the number of files matter when cumulative(?) image size will stay the same?
thanks.[/quote]
The main reason why I posted this question was this: I was using–probably outdated version of–sirisian’s texture manager and every other time, the loader will go into infinite loop. This happens when I try to load up front.
In case anyone is interested, I post the code with a part I added to fix the issue.
package engine.texture {
import flash.display.BitmapData;
public class Texture {
public var loaded:Boolean;
public var ID:String;
public var bitmap:BitmapData;
public function Texture(ID_:String) {
loaded = false;
ID = ID_;
}
}
}
package engine.texture {
import flash.display.*;
import flash.events.*;
import flash.net.URLRequest;
public class TextureManager {
//All the textures.
public var textures:Array;
//Array for textures waiting to be loaded.
public var textureLoadQueue:Array;
public var readyToLoadImage:Boolean;
public var URLpath:String;
public var textureTemp:Texture;
// JK added
public var numItems:Number = 0;
public var numItemsLoaded:Number = 0;
public var loadDelayCounter:Number = 0;
public function TextureManager(URLpath_:String) {
URLpath = URLpath_;
textures = new Array();
textureLoadQueue = new Array();
readyToLoadImage = true;
// Loading graphics
numItems = 3; // hardcoded value
//this.Load("Game_Ending");
//this.Load("CharacterSheet1");
//this.Load("CharacterSheet2");
}
public function Load(imageID_:String):void {
//Allocate a spot to identify if the texture is loaded
textures[imageID_] = new Texture(imageID_);
//Add to the load queue to download the image file
textureLoadQueue.push(textures[imageID_]);
}
public function allLoaded():Boolean { return (numItems == numItemsLoaded); }
public function LoadQueue():void {
if (textureLoadQueue.length>0) {
if (readyToLoadImage) {
loadDelayCounter = 0;
textureTemp = textureLoadQueue.shift();
trace("Loading: "+textureTemp.ID);
readyToLoadImage = false;
var loader:Loader = new Loader();
var urlReq:URLRequest = new URLRequest(URLpath+textureTemp.ID+".png");
loader.contentLoaderInfo.addEventListener(Event.INIT,completedLoading);
loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, errorLoading);
loader.load(urlReq);
} else {
loadDelayCounter++;
trace("Texture Loading...");
// JK _ if it keeps repeating for 5 times or more, try force reloading
if (loadDelayCounter > 5 ) {
//loader.contentLoaderInfo.removeEventListener(Event.INIT,completedLoading);
//loader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, errorLoading);
textureLoadQueue.unshift(textureTemp);
readyToLoadImage = true;
}
}
}
}
public function completedLoading(eventObj:Object):void{
trace("Done Loading: " + textureTemp.ID);
var loader:Loader = eventObj.target.loader;
var info:LoaderInfo = loader.contentLoaderInfo;
textureTemp.bitmap = Bitmap(loader.content).bitmapData;
textureTemp.loaded = true;
readyToLoadImage = true;
numItemsLoaded ++;
}
public function errorLoading(eventObj:Object):void{
trace("Error Loading Image: " + eventObj);
//An error occured. By default the next image will load: NOTE: if needed you may want to uncomment the lines that follow given what you want to do:
//textureLoadQueue.unshift(textureTemp);//This will try to load the image again.
//textureLoadQueue.push(textureTemp);//This will try to load the image again after the rest of the images.
readyToLoadImage = true;
}
//Does not check if the image is actually loaded or exists, just returns the texture if found
public function GetTexture(ID_:String):Texture {
return textures[ID_];
}
}
}
All I added to fix is the little part in LoadQueue(). I also added allLoaded() check function.
Note that this works if and only if you are loading all the files up front; we did it this way for our game since we didn’t have too much graphics AND we got lazy and didn’t want to bother loading at various other places… heh.