Sign in to follow this  

TiledLayer? should I use it

This topic is 3846 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Sorry mates, another one of those please confirm it for me questions. regarding the TiledLayer it enables us to create an image (animated or not) by repeating chunks of a special image (rough explanation). So I create an image that has all my tiles and then use this to create a huge map. My questions come on: Just how big can the map be and will be be rendered effectively? I was considering 32x32 square tiles each 32px wide. That creates a huge map although its quite smaller than what I originally intended. The tiles will be mostly repeated. Also is there any other way to create the tiled layer besides "setCell" or "fillCells"? Yours Truly K PS: I am planning on using a LayerManager with the TileLayer and all my sprites, just in case you wondering.

Share this post


Link to post
Share on other sites
Hi,

I created a 2D platform engine and I didn't use the TiledLayer class since I don't know how this class really handles all the tiles concerning rendering operations. ( a profiling test would be so helpful )

So I just created a class with several Sprite classes, each for every tile I need. With this class and a Camera class I could sort out which tile needs to be rendered ( very useful for levels with scrolling ).

I wasn't sure if TiledLayer class would have rendered also the tiles outside
the current screen area so I just didn't take the risk ( If you do, please let me know about performances! )

Let me know if you are interested to view my source code.

Share this post


Link to post
Share on other sites
hm...
I was hoping for more answers here. I guess its up to me to do the tests :)

Anyways:

1- Using tileStudio I can make both tiles and a map. Its export map function also allows me to output a binary file with the tile numbers (I think, I need to proper test this but Im pretty sure it is a list of tile indexes).
This will allow you to create a huge map, export it to an image and a binary indexes file and then finally create the tiledLayer to read the binary file and create the map tile.

2- As for performance ill let you know soon whats the result. My game requires me to be able to scroll freely across the map so if this messes up performance I will be able to notice it easilly. Plus I have the profiler tools enabled anyways.

Clawer:
Does your code run well? I kinda figure that creating multiple sprites and painting them one by one would be worst.
How do you manage to decide which tiles to paint? I dont mean which is visible, I mean how do you map them? One of my big problems with tiledLayer was the dificulty in creating the map (you have to set each tile one by one). I cant imagine how you handling this.

Yours Truly
K

Share this post


Link to post
Share on other sites
Hi BloodWarrior,

first of all let me tell you I've just uploaded the engine's source code on my website.
If you are interested click here!

Does my code run well? I hope so! :)
Ok, seriously.. I really don't know how much can I get by making things working these way since I didn't spend a lot of time testing the TiledLayer class.
On the other hand I sent a little MIDlet ( with all those MIDP2.0 classes like TiledLayer ) to a friend of mine and I noticed that the cps value was very low!
Ok, let's say that the mobile's cpu wasn't so good to run videogames but now, with my classes, I obtain greater values ( and maybe they could me more optimized too )!

With the TiledLayer class you probably have to map an entire area ( width * height ) with ( width / tileWidth ) * ( height / tileHeight ) tiles.
( Probabily this class isn't so suitable for platform videogames )

With this
the engine in action
I'm just rendering on the screen these x tiles I need in order to setting up the scene.

As you can see from the source code and the image below I have a LevelClass with a TileBox array: every TileBox has the tile's sprite ( since it extends the Sprite class ), a type and coordinates.

how does it work

When we need to render the screen area we check if every single tile is inside the current camera's position ( off course the camera's coordinates are related to the main character's position ).

I must spend a little time talking about TileBox coordinates.
Remember that a Sprite has its own coordinates and in our TileBox class we have these and also "level coordinates"! ( displayed over the tile on the first image )
When we will call the paint() method our Sprite is printed following Sprite's coordinates and NOT our x, y "level coordinates". So that's why we first need to set a new position with

setPosition( x - camera.x, y - camera.y );

Sprite's coordinates has just changed their value and now the Sprite is ready to be printed on the display. Anyway we keep our "level coordinates" in order to perform new operations without "messing" our original data.

Hope this helps,

Share this post


Link to post
Share on other sites
Wow Clawer... thats a lot.

Sorry for replying so late by the way.

I created a png with about 20 32x32 tiles then used TiledLayer to create a 32 by 32 tiles map -> 1024px by 1024 pixels. Thats quite a huge map.

At the moment im only sticking the map directly on the canvas and using button press so that I can freely scroll the entire map.
The code has a background music, displays after both the splash screen and game menu and has a small code that tries to run only in 30fps (sleeping in each cycle if it still has time).

This is running at 24fps (scrolling the map) in my pc emulator (generic) and at 32fps in my nokia 6230i.

So im pretty sure its quite effective. Note that I still dont have much else on screen but then Im also planning to use layermanager (i think thats the right class) so that I can stick an entire world map in it and it will handle the view.

Let me know what you think!
Yours Truly
K

Share this post


Link to post
Share on other sites

This topic is 3846 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this