LoadImage frame count

Monkey Forums/Monkey Programming/LoadImage frame count

Samah(Posted 2011) [#1]
At the moment, to load an image with multiple frames, you must give it a cell width, cell height, and frame count. Is it possible to make the frame count optional, and infer it from the cell dimensions?

Depending on the map tileset I'm loading, I may not know the number of frames or the image dimensions (only the cell dimensions). I'm sure it's as easy as (imagewidth / cellwidth) * (imageheight / cellheight), and just assume that imagewidth and imageheight are multiples of the cell dimensions.


Hima(Posted 2011) [#2]
You can load the whole image and make your own animation/tile system by using drawing from rectangle or create an image from rectangle for each frame. That's what I'm doing in my framework.


wiebow(Posted 2011) [#3]
Samah,

The thing I do is load the whole image first in a temp location, and determine the frame count using the method you described. Then, throw the temp image away and use LoadAnimImage.


Samah(Posted 2011) [#4]
You can load the whole image and make your own animation/tile system by using drawing from rectangle or create an image from rectangle for each frame. That's what I'm doing in my framework.

That's what I've done.

The thing I do is load the whole image first in a temp location, and determine the frame count using the method you described. Then, throw the temp image away and use LoadAnimImage.

That's what I did in the BlitzMax code I'm converting from, but I don't want to mess around with temporary images when mobile devices are a target.

Regardless, it should be a fairly trivial thing to add. I'm not sure why it's not already there...


Hima(Posted 2011) [#5]
You can't really assume that. For example, an animation with 12 frames can be split in to 2 rows 6 columns or 3 row 5 columns where in the last row there are 3 blank columns. Frame count give you more freedom to add images of many size together as well, since you can load a big image and then grab subimage from it using GrabImage method.

As for the mobile target, you only need to do this once so I don't think that'd be too big of a problem if you do it at the start of the game. V40 just added a Discard method where you can release it from the memory so there should be nothing to worry about.


wiebow(Posted 2011) [#6]
Assuming you're not programming the map EDITOR to run on mobile, I don't see why the map metadata could not contain the number of frames to get from the tile image.


Samah(Posted 2011) [#7]
You can't really assume that.

In this case, I can. Besides which, it should be an optional parameter. If you put in the frame count, it uses it. If you don't, it takes a guess. If it gets it wrong... well it's your own fault. :)

As for the mobile target, you only need to do this once so I don't think that'd be too big of a problem if you do it at the start of the game.

Not in this case. It loads up the tileset based on the current map, and I don't want to waste memory by caching all the tilesets at the start of the game if the user never gets to that map. It also forces me to read all the map files at the start of the game.

V40 just added a Discard method where you can release it from the memory so there should be nothing to worry about.

After 7 years of industry-level Java, I don't trust garbage collection at all. :)

I don't see why the map metadata could not contain the number of frames to get from the tile image.

Because I don't have any control over the Tiled map format.
http://www.mapeditor.org/


wiebow(Posted 2011) [#8]
Ah! Well, that is exactly the reason I am making my own map editor and map format as well. =]
I intend the map editor to inspect the used tiles in the map and save out a new tileset with only the needed tiles.


Hima(Posted 2011) [#9]
Hmmm. Maybe it's just me but I don't understand how would you waste much more memory with the loading big image approach.

I take it that LoadImage with frames will make many image references but still load only one large texture. So when you use LoadImage, you would have to load the large texture in anyway.
This should be the same as loading a large texture in one Image reference, and then use Image.GrabImage to create a reference with all tiles from it.

The only difference that I see is the former one doesn't have an Image reference to the large texture while the other one does. I doubt that one reference will cost much memory that you immediately need it back though. :S

As for map editor, if you want the one that you can control your format, maybe you should try DAME editor or Ogmo editor. They're AIR based editor. I've tried Ogmo and it's very good, though it takes a while to setup, but it allows you to cuztomize yourown XML so it's pretty flexible. Haven't really tried DAME so can't say much about it though :O


wiebow(Posted 2011) [#10]
Thanks for the information about the editors, hima. I will take a look. The editor I want to make will also create maps I can use in my Blitzmax games, so I like to be in control of what it does and how it looks cos I will be using it a lot.