View Full Version : Fun (help) with tiles!
ShooterMG
August 23rd, 2007, 11:51 AM
Greetings, all. I'm currently working on a tile based game, but that's pretty much where i've hit the wall. Does anybody know of a good way to load and store external bitmap images so I can use them as tiles? Currently it's set up so the bitmap loads whenever the tile gets created, but that ended up being way to slow in a browser. If there was a way where I could just load each bitpmap once somehow, and use the bitmap data whenever the appropriate tile was needed, that would be great. One other option I was trying to work with was to import them all into the library, but then they would each have to have their own specific class, which is not good. Any advice would be great! Thanks
tiboO
August 23rd, 2007, 12:13 PM
I dunno if the problem is really to handle several loaded image... I believe it's more a problem of having them displayed even if they are out of the view.
You could perhaps firstly try to simply display only the tiles which are viewable.
Though i'm sure you can google a bit and find some game-tile manager very easily, there are a lot.
Charleh
August 23rd, 2007, 12:17 PM
You don't need a specific class for each bitmap - you just declare one class and load in the bitmap data from the library based on the linkage name. You should be able to link the files that you are importing into the library at runtime (though I've not done it before myself)
ShooterMG
August 23rd, 2007, 12:25 PM
You don't need a specific class for each bitmap - you just declare one class and load in the bitmap data from the library based on the linkage name. You should be able to link the files that you are importing into the library at runtime (though I've not done it before myself)
Ahhh, excellent. This is what I was hoping to hear. Thank you!
butcherBaker
August 23rd, 2007, 12:27 PM
Greetings, all. I'm currently working on a tile based game, but that's pretty much where i've hit the wall. Does anybody know of a good way to load and store external bitmap images so I can use them as tiles? Currently it's set up so the bitmap loads whenever the tile gets created, but that ended up being way to slow in a browser. If there was a way where I could just load each bitpmap once somehow, and use the bitmap data whenever the appropriate tile was needed, that would be great. One other option I was trying to work with was to import them all into the library, but then they would each have to have their own specific class, which is not good. Any advice would be great! Thanks
you can load all your images, prior to any display. each image would need it's own loader.
then you can make a new BitmapData object in a sprite. then, the eventListener for the loader's onComplete would move the loader.content over to the sprite.BitmapData, thereby removing it from the loader.
I guess actually you could have one loader and one listener and a queue, when the onLoad Event is broadcast, you'd create a new spriteBitmap with a BitmapData (inside of your tile I guess) you'd copy the loader.content to the sprite's bitmap data (by referencing the loader.content and adding it to another display list), increment the cue counter, then call the loader to load the next image in the cue. I think that would work pretty cleanly.
Templarian
August 23rd, 2007, 12:27 PM
http://www.kirupa.com/forum/showthread.php?t=264619&highlight=texture+manager
... maybe this... It basically loads images into bitmaps. I barley know AS3 so I can't help only show what I've seen others use.
ShooterMG
August 23rd, 2007, 12:41 PM
http://www.kirupa.com/forum/showthread.php?t=264619&highlight=texture+manager
... maybe this... It basically loads images into bitmaps. I barley know AS3 so I can't help only show what I've seen others use.
Hmm, that looks kinda nice.
Also apparently you can only link one class to one library object, so that idea is out.
Charleh
August 23rd, 2007, 02:20 PM
Well then, dont link your class to your library object!?
Just instantiate the class then pick up the library object for display purposes...you don't need to link them together
For instance in my game I have a class that contains a movieclip reference - I can load any library object into this movieclip reference therefore changing the graphic for any given object at any time.
You could also extend MovieClip with your class and just load the movie into the clip placeholder
ShooterMG
August 23rd, 2007, 02:44 PM
Well then, dont link your class to your library object!?
Just instantiate the class then pick up the library object for display purposes...you don't need to link them together
For instance in my game I have a class that contains a movieclip reference - I can load any library object into this movieclip reference therefore changing the graphic for any given object at any time.
You could also extend MovieClip with your class and just load the movie into the clip placeholder
Would you mind giving me an example of some code? I'm not familiar with loading library objects into dynamically instantiated classes.
ShooterMG
August 23rd, 2007, 04:36 PM
I'm just not really sure how to take a png in the library, and instantiate it in an existing movieclip created with AS.
endemoniada
August 23rd, 2007, 08:15 PM
I'm very new and still learning but this is what I did:
I didn't put any images in the library, I loaded them like this:
var bitmapinfo:BitmapInfo;
var loader:Loader=new Loader();
loader.contentLoaderInfo.addEventListener(Event.CO MPLETE,loadComplete);
var request:URLRequest=new URLRequest("deck.png");
loader.load(request);
private function loadComplete(event:Event) : void {
// make sure you know the dimensions of the .png
bitmapData=new BitmapData(pngWidth,pngHeight,false,0x000000);
bitmapData.draw(loader);
}
...at which point you'll have the bitmapInfo filled with the .png
That could be your image with all the tiles, then you would use copyPixels() to blt the individual tiles.
I hope that helps.
butcherBaker
August 24th, 2007, 12:29 PM
I'm very new and still learning but this is what I did:
I didn't put any images in the library, I loaded them like this:
var bitmapinfo:BitmapInfo;
var loader:Loader=new Loader();
loader.contentLoaderInfo.addEventListener(Event.CO MPLETE,loadComplete);
var request:URLRequest=new URLRequest("deck.png");
loader.load(request);
private function loadComplete(event:Event) : void {
// make sure you know the dimensions of the .png
bitmapData=new BitmapData(pngWidth,pngHeight,false,0x000000);
bitmapData.draw(loader);
}
...at which point you'll have the bitmapInfo filled with the .png
That could be your image with all the tiles, then you would use copyPixels() to blt the individual tiles.
I hope that helps.
Alternatively, you could avoid having to get the pngWidth & pngHeight
public function onComplete(e:Event):void {
var image:Bitmap = Bitmap(_loader.content); // cast loader content as Bitmap
var bitmap:BitmapData = image.bitmapData;
addChild(image);
}
this just makes the bitmaps equivalent, instead of having to feed the bitmapData a rectangle derived from the width and height of the loader.content.
I haven't used this yet, but am going to try it soon. I believe when you add it to the Display Object, you're removing it from Loader's Display list. and then that loader can be used again in a queue. I expect I'll use the onComplete to increment the queue and call load() again.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.