Tilesheet options?

23 posts

Flag Post

I’m about to begin work on a huge open-world RPG with 32×32 pixellated graphics. Including a huge tilemap for the background. There’s going to be thousands of tiles and I’m really not sure how I’m going to do it.

I’ve used arrays before, where flash just creates an object in accordance to the index in the array. But the rooms were only 20×20 and there were only about ten different objects.

Is there a more… economic way of doing it? I don’t mean the drawing of the tiles, I mean actually writing down the information for flash to read.

 
Flag Post

Writing the information into a ByteArray and then encoding the ByteArray into base 64 code?

 
Flag Post

In the platformer I’m making right now, I’ve had to solve the same problem, here’s how I did it (then I’ll explain why I wish I hadn’t done it this way):

I created a Tile class, which lists all of the different kinds of tiles that exist (air, stone, spikesup, spikesdown, etc…) each corresponding to an integer code. The level map is an Array of Arrays of integers. Each Array of integers is a row of the map, the Array of rows makes the full map, each integer is code for the corresponding tile.

Advantages: each integer takes up 4 bytes, so if I make a 1000×1000 level I’ll use only about 4MB of memory. Trivial in terms of memory usage, but somewhat big in terms of local storage. Technically, as long as I have fewer than 256 kinds of tiles, I could compress that array to a quarter of its size, which may or may not be more efficient than using one of the compression schemes inherent in the ByteArray class when serializing for saving.

Inconvenients:

I cannot store any information about a specific tile in the Array. All tiles of type, say, 27, are the exact same. If I want a wall that can be broken by bashing it repeatedly (N times), I need N types of tiles, and I must alter the tile type at the proper position when the player bashes it. If the player can do varying amounts of damage, the number of tile types needed quickly gets ridiculous. Worse, I have laser tiles, which shoot laser rays at specific intervals. All information about the firing rate and current position in the sequence for one particular laser has to be encoded somehow, somewhere else. In general, any animated tile is going to cause trouble unless you’re comfortable with all the tiles of that type animating at the same pace and in sync.

A single Tile class contains all the information about the way tiles behave. While that’s good in theory, in practice it means the class gets bloated with a lot of stuff that is particular to one kind of tile. I’d have been better off creating a base Tile class for the common properties and extending it as needed for specific Tile subtypes.

Every call to the level Array must then go through the Tile class to figure out what the int returned by the level Array means. Sometimes I wish my level Array contained references to instances of archetypical tiles. Say if level [3 ] [5 ] is a stone tile, instead of having level [3 ] [5 ] contain the int that means ‘stone’ in Tile, have it contain the reference for a stone tile object. Then I could directly access the properties of that object and, unless I’m mistaken, my array wouldn’t be any longer (is a memory address 4 bytes or 8?)

To make a long story short, you’re right to plan how you’re going to do this carefully. People with more experience and knowledge than I have are likely to post too, you’d be wise to learn from my mistakes and listen to their advice. I hope you find a way to do it that works and is convenient to you.

 
Flag Post

A memory address in Flash (x32) is 4 bytes long, so no extra should be stored. And I expect this will be the best combination of array-based and list-based tiles, if one could have an array of tile types, and a list with pair of (x,y) with corresponding data, in case of lasers, current frame and pulse length for example, then when you build that level out of this info, you will need to iterate through the list only, and all the similar tiles will behave uniformly unless explicitly otherwise specified.

 
Flag Post

Yeah it’s only a background, so I’m not concerned about animations being identical, and there’s nothing else to worry about. I think I’ll have a simple array for the tilemap, and a much more complex array for objects, walls, and NPCs.

 
Flag Post

One word. Blitting.
Two words. Dirty Blitting.
Four Words. You can do it.

 
Flag Post

dirty blitting?

 
Flag Post

Animate the bits that are moving, put the bits that are not on a separate bitmap. But I thought you would have known a bit about blitting already.

 
Flag Post
Originally posted by jasonjie88:

Animate the bits that are moving, put the bits that are not on a separate bitmap. But I thought you would have known a bit about blitting already.

Actually that game wasn’t blitted at all.
I actually created objects and then drew them in the object’s class. :P

I kind of know how to blit. You use copyPixels to only draw the section of the sheet you need. And you redraw it every frame.

 
Flag Post

Brilliant idea: make a god-awfully large bitmap (32000×32000) in photoshop which is the background and just move it around. What could possibly go wrong????

/“brilliant idea”

 
Flag Post
Originally posted by feartehstickman:

Brilliant idea: make a god-awfully large bitmap (32000×32000) in photoshop which is the background and just move it around. What could possibly go wrong????

/“brilliant idea”

That did actually occur to me at one point… >.>

I know what I’ll do. I’ll make a program that will be my world editor. Then I can make the world exactly how I need it, and with ease. And then it will spit out the array or string or whatever and I can just copy+paste it into my class. :D

 
Flag Post

http://www.ogmoeditor.com/ can do that for you…

 
Flag Post

But be careful with the beta 2.0 version: it’s not entirely stable and can screw up the level files to the point it cannot open them anymore, even though there is nothing different about them. Quite uncanny.

As for having a huge bitmap as background, why not, but don’t scroll it around. Keep it hidden and copypixels() the appropriate portion onto your screen bitmap every frame.

 
Flag Post
Originally posted by Ace_Blue:

As for having a huge bitmap as background, why not, but don’t scroll it around. Keep it hidden and copypixels() the appropriate portion onto your screen bitmap every frame.

The problem with that is that I might use the same tile 1000 times, and that one tile would take up 1000 times as much space as it would if I copied it 1000 times.
Multiply that by even a small number as 100 tiles and we have a rather large game don’t we?

Originally posted by DPbrad:

http://www.ogmoeditor.com/ can do that for you…


That’s brilliant. I’ll definitely try it out!

 
Flag Post

“Tiled” Editor looks very nice also.

 
Flag Post

I’d recommend TILED over ogmo any day. Its much much more stable. The sheer stability and lag of ogmo made it unuseable for my level projects. Sure, ogmo has a lot of super nice features (like giving data to instances placed on a map) but you, for faster editing and using, are going to find TILED a much better program.

 
Flag Post

I hadn’t heard of Tiled Editor before, I have only been playing around with it for 15 minutes and already prefer it to Ogmo Editor. Thanks for pointing it out.

 
Flag Post

That was the first thing I noticed too. I tried to make a map that was thousands and thousands of tiles across, and it crashed. :( Tiled it is.

 
Flag Post

Not sure if people didn’t see that my post was meant to be sarcasm…
Or if they’re just playing along with the joke.

 
Flag Post
Originally posted by feartehstickman:

Not sure if people didn’t see that my post was meant to be sarcasm…
Or if they’re just playing along with the joke.

Or perhaps a bit of both! Everyone appreciates sarcasm, but sometimes sarcasm leads to good ideas. xD (as well as some not-so-good ideas)

 
Flag Post

well, you violate maximum bitmap size that’s possible in Flash 10+, so your idea is obviously a fluke. However, testing products to the extremes (like they do with tile editors) rocks.

 
Flag Post

Yes, definitely do not make a huge bitmap. Depending on what your doing exactly, breaking the huge map your talking about into smaller “chunks” which can be loaded seperately is a better idea. Similar to Pokemon games, where each area is split up and when you enter or a new area, it will unload the previous and load in the new one. Having a huge dynamic world loaded in memory is a bad idea.

 
Flag Post

Most people use one bitmap so they can monitor all objects in the world in real-time. I suggest using a time-measurement and monitoring only the things that are able to move into your screen.