PDA

View Full Version : New TileMap example



sphair
04-03-2011, 08:19 PM
An new example in the ClanLib SVN (for the 2.2.8 release)

TileMap demonstrates a simple smooth-scrolling, multi-layered tilemap engine.

The tilemap level is defined in a resource file, and can contain any number of layers.

http://clanlib.org/w/images/c/cf/Example_TileMap.png

Maciej Baron
04-04-2011, 10:37 AM
That's great, just what I needed.

Quick question (I haven't had a look at the source code yet), will it be possible to scale the tilemap?

sphair
04-04-2011, 02:33 PM
The drawing part of the example is just really simple - about 40 lines of code. I'm sure you can find ways to scale the entire tilemap, for instance by calling set_scale on the tilemap sprite and calculating the screen positions accordingly. You could also perhaps set scale on the entire gc... many options :)

Maciej Baron
04-04-2011, 03:04 PM
Cool. I wrote something similar myself, but I'm not using any buffering, so it's a bit slower then it could be.

I've tried scaling the entire gc but I can't seem to disable linear scaling (I want to achieve a retro effect).

I'll have a look at your code in the evening. Thanks!

EDIT:

I had a look at your code. It's nice, but unfortunately it doesn't solve my problem.

Is there a way of "pre-rendering" the map instead of rendering all the sprites at every iteration? I found some examples using CL_Surface and CL_Canvas, but these don't seem to be available anymore...

rombust
04-04-2011, 07:47 PM
CL_Surface and CL_Canvas (from Clanlib V1.0) are now known as CL_FrameBuffer

The canvas example is still there, Examples/Display_Render/Canvas http://clanlib.org/wiki/Canvas

rombust
04-05-2011, 08:11 AM
I've tried scaling the entire gc but I can't seem to disable linear scaling (I want to achieve a retro effect).

...

Is there a way of "pre-rendering" the map instead of rendering all the sprites at every iteration?

This is not required. For my methane brothers game, I render the 20x20 blocks (16x16 pixels per block) tile map every frame. This is still very fast.

Also my game scales the entire gc and disables linear scaling.

The game used to render the map to a buffer and blit the buffer every frame. But, I removed that to simplify the code.

( http://methane.sourceforge.net/ )

Maciej Baron
04-26-2011, 01:15 PM
But if I were to buffer the output beforehand? I will be rendering well over 20x20 blocks on the screen (I will be covering the whole screen with blocks that are 32x32 pixels) so that might be a lot of blocks. Moreover I will have several layers of objects.

What would be the best solution?

rombust
04-27-2011, 08:03 AM
In the past (around 1990's), it was slow drawing an entire screen.

You needed to use "damage maps" to only draw areas that have been updated.

With OpenGL, you would need to draw to the screen buffer (CL_FrameBuffer), then each frame copy the screen buffer to the screen.

That's how clanGUI Texture Window manager works.

...But...

If you are using OpenGL (clanGL1 or clanGL), it is sometimes faster to redraw the entire screen, without a screen buffer.

The Pacman example redraws the entire tile map (51*51 tiles at 28x32 block size) at 1000fps.

Internally ClanLib batch draws graphic operations, which is very fast.

halley62373
06-25-2011, 10:51 AM
It's a excellent example.

Refpeuk
11-01-2011, 12:19 AM
I'd like to see your source code. Is there a place I can download it? I might just be blind, but as far as I can tell the page on the ClanLib wiki only has a picture and description . . .

sphair
11-01-2011, 07:21 AM
http://clanlib.org/wiki/Download

Download the source package, it has all the ClanLib source and examples.

Refpeuk
11-01-2011, 08:06 PM
http://clanlib.org/wiki/Download

Download the source package, it has all the ClanLib source and examples.


OK, thanks, I didn't realize you had to download them all at once.