Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Mappy tilemap engine playback library port for SFML  (Read 41457 times)

0 Members and 1 Guest are viewing this topic.

Breakman79

  • Jr. Member
  • **
  • Posts: 58
    • View Profile
Mappy tilemap engine playback library port for SFML
« on: March 20, 2010, 07:32:12 am »
Hi fellow SFML programmers.  Since I'm new here I thought I'd start off by posting something that I think a lot of people would find useful.  I didn't see any finished SFML tilemap engines so I ported Mappy's to SFML and C++ as an exercise in learning C++


The library can display:
    Regular
    Hexagonal
    Depth sorted Isometric maps
    Parallax backgrounds
    and all with built in map animations


New Release: May 19, 2010

Issues Fixed:
-Tile #0 is no longer drawn.  This was causing a transparency issue with maps using images greater than 8-bit color depth and drawing more than one layer.

Improvements:
-Added SetMapStartPosition and SetMapDimensions functions while overloading some of the drawing functions so those values can be set once instead of being passed every time.  Overloaded the constructor so that map filename, and the position and dimensions can all be set at once.

Other Notes:
-The Demo isn't working quite as well in this release as the last.  I was working on rewriting but I wanted to get the fix out for WitchD0ctor so I left it as is.  Need to overload the DrawMapParallax and DrawMapRow functions.

The new download can be found here: http://www.mediafire.com/file/kwczgm5wzzn/SFMLMappy_2010_05_19.zip


The Mappy TileMap editor can be found here: http://www.tilemap.co.uk/mappy.php


Questions, comments, bugs reports are greatly welcomed.

Nothingness0x

  • Sr. Member
  • ****
  • Posts: 292
    • View Profile
Mappy tilemap engine playback library port for SFML
« Reply #1 on: April 01, 2010, 12:50:36 am »
one question : How do you put collisions ? And how it is saved on the file ? (wanna know to know how to program the map reader)

Can we use animated tiles like water ? How

Thanks and good job

Breakman79

  • Jr. Member
  • **
  • Posts: 58
    • View Profile
Mappy tilemap engine playback library port for SFML
« Reply #2 on: April 01, 2010, 06:26:36 pm »
In the Mappy editor you can add the collision information by double clicking on a graphic block in the "Still Block" area which brings up the "Block Properties" screen.  On it there is a section for Collisions with check boxes for top left, top right, bottom left, and bottom right.

To retrieve the collision information using the playback library you can use the GetMapBlockInPixels method.  It returns a struct containing all of the information of the graphic block located at position at the requested x and y coordinate with 0,0 starting at the top left of the map.

Yes, you can add tile animations.  In the editor if you right click on the "Still Block" area it will switch to "Anim Blocks" where you can add a new block (Ctrl-N) and double clicking it you can add the different animations, delay, and how is it looped.  The zelda.fmp map I included in the download has a bunch of example animations including some simple water animations.

Let me know if you need anything else.  I'm still working on this library to add more improvements and hopefully I'll have time to create a simple game for an example.

Nothingness0x

  • Sr. Member
  • ****
  • Posts: 292
    • View Profile
Mappy tilemap engine playback library port for SFML
« Reply #3 on: April 02, 2010, 01:50:52 am »
Yes I still have some other questions actually :

1)Can I load my own tiles on the editor ?
Or do I gotta use only specific tiles provided by the editor ?

2)and If for exemple I put a tree on my map, how do you manage the fact that the character can pass behind the tree without being blocked (I mean the character pass behind the tree and disapear behind because the tree is draw after the character ), whereas if the character pass in front of the tree, the tree is drawed after the character because the character is in front of the tree, and the collision area must be somewhere in the middle of the character.


3) When you click on a tiles or a groupe of tiles, it would be great if your mouse pointer take the image of the tiles you clicked on, because it's hard to aim with the basic mouse pointer and you dunno what you took, because right now all i see is a white thing.

4) is it possible to take several tiles at the same time ? I mean if i have a house who is made of 6 tiles for exemple, I should be able to take the whole 6 tiles house at the same time and draw it on the map without having to draw my house tiles per tiles

5) If i create a map and save it, is it save on a .txt ? I have to know how its saved to know how to developp my map reader inside my game ...

6) The version i download here http://www.tilemap.co.uk/mappy.php  is the sfml/c++ version right ?

I hope you understand what i mean cause my english is not perfect .... sorry about that.

thanks

Breakman79

  • Jr. Member
  • **
  • Posts: 58
    • View Profile
Mappy tilemap engine playback library port for SFML
« Reply #4 on: April 02, 2010, 04:50:36 am »
Ok, I think you are confusing some things here.  I'm not the author of the actual Mappy map editor.  I simply ported the playback library, the part you would include in your game, from using a Direct X media library to instead work with SFML.

The source code I provide in the download link is a class you can include in your game to load and display any map created with the Mappy editor along with methods for doing things like the collision detection and updating the map animations.

I can answer some of your questions about the editor though:

1) You can load any tiles you want as long at they are all the same size based on what you define when you create a new map.  They all need to stored in a single file that you load using File->Import.  

2) For something like a tree you need to split it up into multiple tiles.  The roots being in with the collision flags set and the graphic set to the BG layer.  The top of the tree would be in another tile with no collision and set to the FG1 layer.  

3) Since I didn't make the editor there isn't anything I can do about it, but I think that would be nice as well.

4) Yes, the Brush menu lets you create brushes made out of multiple tiles.

5) The maps are normally saved in a binary format. I believe you can use File->Export as text to make something different.  The map reader you talk about is the part that I actually have already made and linked in the first post which you can reuse for your game.

6) That's the Mappy author's website where you can download the editor and the playback libraries for different game and media libraries (One didn't exist for SFML so made it)

Walker

  • Full Member
  • ***
  • Posts: 181
    • View Profile
Mappy tilemap engine playback library port for SFML
« Reply #5 on: April 13, 2010, 07:27:28 am »
I found mappy a few days ago and dreaded the thought of working it into SFML. I've been playing around with your port a bit and it seems to do everything I need at the moment.

Have you made any more progress? Are you still planning to create a bit of an example on how to use it? I've been working through the Allegro example but I don't have the Allegro library so a working example I can compile and run would be great.

Cheers :)

Breakman79

  • Jr. Member
  • **
  • Posts: 58
    • View Profile
Mappy tilemap engine playback library port for SFML
« Reply #6 on: April 13, 2010, 11:14:20 pm »
Hi Walker.  Yes, I'm still working on improving the port.  I added a new download in my original post with an updated version of the class along with two examples and a small demo showing how the map collision detection would work for some simple AI sprites.  

I've been pressed for time lately so I didn't comment it very well, but I'll definitely answer any questions that you have.

Walker

  • Full Member
  • ***
  • Posts: 181
    • View Profile
Mappy tilemap engine playback library port for SFML
« Reply #7 on: April 14, 2010, 04:30:20 am »
Excellent, I'm starting to understand the collisions and other tile info stuff now. I think.

Code: [Select]
GetMapBlockInPixels(x, y)

Returns the BLKSTR struct for the tile at PIXELS x, y? GetMapBlock(x, y) returns BLKSTR for TILE x, y?

Code: [Select]
if(TileMap.GetMapBlockInPixels(pos1x,pos1y)->tr) return true;

Basically checks if the 'tr' box in the editor was checked? I can't seem to get this to work in my own code.

How do you check the value one of the User variables?

Breakman79

  • Jr. Member
  • **
  • Posts: 58
    • View Profile
Mappy tilemap engine playback library port for SFML
« Reply #8 on: April 14, 2010, 06:39:28 am »
Quote
Returns the BLKSTR struct for the tile at PIXELS x, y? GetMapBlock(x, y) returns BLKSTR for TILE x, y?

That's exactly right and it's based on the map coordinates.  So if you're looking for the collision on a block that currently showing up at say position 100,100 on the screen, but you've scrolled the map 400 pixels to the right then you need to be calling GetMapBlockInPixels(500,100)

I was only doing a simple collision check for the whole tile by only checking the top right value.  You make it as simple or complicated as you like using the 4 checkboxes.

Checking for the User vars should be as simple as:
Code: [Select]
unsigned long int User1;
User1 = Map.GetMapBlockInPixels(x,y)->user1;


User1 and 2 are unsigned long ints, 3 and 4 are unsigned short ints, and 5, 6, and 7 are unsigned chars.

Hmm, I haven't had any problems with using GetMapBlockInPixels unless you request something out of range and then it will crash.  The function works on whatever current layer you have selected, so if you change to one to draw some rooftops or something and forget to change back before running your collision detection, that would be a problem.

If you can't work it out, I could take a look at your code to see what I can figure out.
[/quote]

Walker

  • Full Member
  • ***
  • Posts: 181
    • View Profile
Mappy tilemap engine playback library port for SFML
« Reply #9 on: April 14, 2010, 07:37:44 am »
Oh of course, I was experimenting just after my drawing routine so I was on a different layer than what I thought.  :oops:

Cheers

WitchD0ctor

  • Full Member
  • ***
  • Posts: 100
    • View Profile
    • http://www.teleforce-blogspot.com
Mappy tilemap engine playback library port for SFML
« Reply #10 on: April 22, 2010, 11:27:04 am »
How can you make the background transparent, like the allegro version has
MapDrawBGT, in the header it says DrawMapBG is the same, but it draws Black where the empty space is, is there a way around that?
John Carmack can Divide by zer0.

Breakman79

  • Jr. Member
  • **
  • Posts: 58
    • View Profile
Mappy tilemap engine playback library port for SFML
« Reply #11 on: April 22, 2010, 03:55:17 pm »
The background should already be transparent.  DrawMapBGT is redundant because in SFML all sprites are drawn using their alpha transparency by default.

Are you drawing anything to the screen before calling DrawMapBG?  A simple way to test that it's working is to change the Clear function so that it clears the screen to a different color other than black to test.

If you're using the code from one of the examples change the App.Clear line to this:

App.Clear(sf::Color(255, 0, 0));

That should make all of the transparent areas show up as red.

Let me know if you are still having problems.

WitchD0ctor

  • Full Member
  • ***
  • Posts: 100
    • View Profile
    • http://www.teleforce-blogspot.com
Mappy tilemap engine playback library port for SFML
« Reply #12 on: April 24, 2010, 11:08:41 am »
Still having issues, i thought it might be the map, but all of the tiles have BG transparency checked. any idea what's going on?
John Carmack can Divide by zer0.

Ashenwraith

  • Sr. Member
  • ****
  • Posts: 270
    • View Profile
Mappy tilemap engine playback library port for SFML
« Reply #13 on: April 26, 2010, 02:50:24 am »
Hey, have you thought of porting to Tiled:

http://www.mapeditor.org/

It's open source and has free features you don't have to pay for like placing map objects. You also don't need to download separate files for png support.

Plus it supports windows/mac/linux.

The original version was done in java, but the new version is done in C++ with Qt.

Walker

  • Full Member
  • ***
  • Posts: 181
    • View Profile
Mappy tilemap engine playback library port for SFML
« Reply #14 on: April 26, 2010, 03:28:49 am »
Tiled is good, but this is the SFML Mappy thread. Placing objects with Mappy really isn't very difficult to work out. AFAIK, Tiled doesn't already have map loading code for SFML.

I don't think switching to Tiled would be a good move at this stage, you're bound to run into just as many issues with that plus you would have to rewrite everything.