Invalid bitmapdata.. xml and even MORE annoying stuff to deal with


(John Andersson) #1

Okay. Jacked from another thread:

Okay, so now I don’t understand what the hell is going on.

I figured the tileset was too big (since it was originally 480x480 and I wanted to scale it sixfold), so I went ahead and optimized the TMX file with a Tiled plugin. Basically you save the Tiled map in base64, run some magical python plugins, and it outputs two files.

Your original TMX file, but optimized (and still in base64), and a new tileset image. This tileset image only contains tiles that are actually being used by the TMX file.

So it’s basically a dream come true. Now, what I did was open the optimized file in Tiled, resaved it as XML (since I only know how to parse XML), and then we come to my game, which handles the scaling. Note that the new tileset image is only 96x96, and scaling it sixfold will make it “only” 576x576. I think that’s pretty damn good for an entire level.

So here we go, time to actually make it work with the game. F**k yeah! Oh wait, no! I still get the same “invalid” bitmapdata error. So is it even about memory? Is there some curse I have been carrying since birth? Is flashpunk disliking me as a user? What is going on here?

I will provide you with the entire source code of the gameworld (it handles the level loading), please take a look and see if you find any mistakes!

package game_handling { imports here

public class GameWorld extends World { [Embed(source="…/assets/circle_gradient2.png")] public static const SPR_LIGHT_CIRCLE_GRADIENT:Class;

vars here, and:

private var _map_Ground:Tilemap;
private var _map_BG2:Tilemap;
private var _map_BG1:Tilemap;

public var collisionData:Grid;

//Level1
[Embed(source="../../levels/ConvertBase64/output/Level_1/level_1_xml.tmx", mimeType="application/octet-stream")]private const LEVEL1:Class;

[Embed(source="../../levels/ConvertBase64/output/Level_1/Dungeon_1.png")]private const DUNGEON_1:Class;

(Jacob Albano) #2

In your comments in the other thread you said your tilemap was 19201080, but now you’re saying it’s 9696? Are you sure you don’t mean each tile is 96*96?

In any case, the “Invalid BitmapData” error will only ever be thrown if you attempt to create a BitmapData object of a resolution higher than 4095*4095. It’s not happening at random or because of your personality.


(John Andersson) #3

Oh, ehm. It’s 96x96 right now. I’m 100% positive it is.

Yep, just checked… 96x96


(John Andersson) #4

Okay, so I actually pulled my head out of my arse and tried some real debugging. It seems like this line:

trace(mapWidth * 128)

gives me a REALLY high number.

mapWidth is apparently 151515, probably 15 from layer one, 15 from layer two and 15 from layer three.

So I should make mapWidth this width:

<map version="1.0" orientation="orthogonal" width="15" height="9" tilewidth="16" tileheight="16">

Something like

var mapWidth:uint = uint(mapXML.@width);

But I can’t seem to find the right text to write

EDIT: Okay, it seemed to do the trick.

But I get a new error, yay

 Invalid tileset graphic provided.

I will try to find the solution


(John Andersson) #5

Okay so I googled it… but I can’t seem to find any good information. I only see two lines in the source code of FP but I can’t figure them out


(John Andersson) #6

Also, if I

trace(mapXML.layer.attribute("name"))

then I get

BGGroundGround_Accessories

How do I make it trace each one individually?

Because when I try to load the data, as you can see I have

var layers:String = mapXML.layer.attribute("name");
switch (layers)
{
	case "Ground":
		if (tile.@gid != 0)
		{
			collisionData.setTile(tileX, tileY, true);
		}
			
		if (tile.@gid != 0)
		{
			_map_Ground.setTile(tileX, tileY, uint(tile.@gid - 1));
		}
		break;
					
	case "BG":
		if (tile.@gid != 0)
		{
			_map_BG1.setTile(tileX, tileY, uint(tile.@gid - 1));
		}
		break;
					
	default:
		trace("NOTHING")
}

and it always traces “NOTHING”


(Zachary Lewis) #7

You might have better luck with the E4X approach to XML processing. It’s what I’m using to parse through the XML list in zachwlewis/tiled-flashpunk.


(Robert) #8

Hope it’s OK to bump this. As it so happens I’m running into a similar problem.

First off: Thank you, Zach for all the tutorials and examples. I adapted your code here, and it works like a charm!

However, if I add another layer in Tiled I get an “invalid bitmap data” error when I run the program. I’ve confirmed that it’s properly reading the layer I have. I can get it to only add tiles from a given layer name, but if there’s a second layer at all I get the error.

Any clues what might be going on?

EDIT: Sorry about the bump. Started a new topic here.


(Jacob Albano) #9

Since your question has nothing to do with the actual issue of the original post, we’d appreciate it if you made a new one instead of resurrecting this one. In your post, please also show the code you use to load the levels, pared down to just what you think is relevant to the problem.