Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for external tilesets #16

Closed
osro opened this issue Nov 25, 2012 · 23 comments
Closed

Support for external tilesets #16

osro opened this issue Nov 25, 2012 · 23 comments

Comments

@osro
Copy link
Contributor

osro commented Nov 25, 2012

https://gist.github.com/9cde603db32d1d58b8b2

I've tried to add a support for external Tileset files in Tiled maps.

Loading part works fine, but the problem is that ObjectMaker2D will process the map file before these asynchronous loader events occurs.

Any suggestions how this could be solved?

@alamboley
Copy link
Member

We may use a Signal : when the map is loaded or is already included in the tileSets we dispatch a Signal. And then we process the map.

However we have to be careful if we use multiple external tileSets.

@alamboley
Copy link
Member

I've working on this, take a look on the last update : 5abd134
With the example updated : https://github.com/alamboley/Citrus-Engine-Examples/blob/master/src/tiledmap/TiledMapGameState.as

If we have several tilesets png and don't want to embed them, we have to load all of them before using something like LoaderMax...

Hope that help!

@osro
Copy link
Contributor Author

osro commented Nov 27, 2012

Ok, I updated my gist slightly https://gist.github.com/9cde603db32d1d58b8b2

I'm not sure is this a best practice, but it works for me at least :)

I had to move TmxMap loading outside the constructor because otherwise it process the level before I can add a listener to it.

Also my FromTiledMap takes now the whole tmx object as parameter this way I can make sure that external files are loaded before I process it.

... and this version of FromTiledMap uses TextureAtlas instead of actual images.
I did not yet update it to use multiple texture files (referring to your last post)

@alamboley
Copy link
Member

We have two differents approach :) For me, we shouldn't load external tilesets into the TmxMap, but load them before and give them as an argument, like I did. I don't pretend this is the best solution, but loading directly in the TmxMap class we have to be sure to do it in a modular way so users won't have problem: e.g. offering the path as an argument (it might be on mobile, ect...).

Using QuadBatch and TextureAtlas make it greatly optimized for Starling!
However I'm not sure to understand the goal of this line :
(ce as StarlingCitrusEngine).starling.stage.addChild(qb);
Why did you add the qb on the stage? At the same time you provide CitrusSprite with the same qb, you may experiment some overlapping.

When I've designed this exporter, I'd in mind that it should works with flash display list and Starling, so I used Bitmap which is not the most optimized solution. Maybe I should dissociate those version and create a new ObjectMakerStarling class.
I didn't use a lot this editor/exporter so any feedbacks is welcome! We may have a new tutorial made by Lee Brimelow using this Tiled Map Editor, it will provide us informations on what people need.

@osro
Copy link
Contributor Author

osro commented Nov 28, 2012

Yep. Those external tilesets will help me so much as a programmer, because I can make those tileset files separately from the levels and then just give those to level designers. I have gave up on hope to explaining how to add custom variables to tiles :D (Our level designers are not "REAL" level designers)

(ce as StarlingCitrusEngine).starling.stage.addChild(qb);
Just ignore that :D It was something that I tried out when I had problems Feathers overlaying everything.

... but yeh, ObjectMakerStarling sounds awesome aswell.

@alamboley
Copy link
Member

Hey Ossi, I'm definitely considering your solution with tiled maps using quad batch and creating an ObjectMakerStarling class, optimized!

Would you mind to provide me an example/samples using a TextureAtlas? Thanks again!

@alamboley
Copy link
Member

Ok, I got it working! However do you also have a "line" between each tile? They come from the background, if you change its color, it'll change the color line.

@alamboley
Copy link
Member

I've make a new build so it can be tested : http://citrusengine.com/v3-0-4-meets-the-dragon/

@osro
Copy link
Contributor Author

osro commented Nov 29, 2012

I haven't tested it yet but the line thing sounds like the problem that I had earlier.

Check out this thread
http://forum.starling-framework.org/topic/tile-map-issue-with-starling

@alamboley
Copy link
Member

Thanks a lot, it made the trick! :)

@osro
Copy link
Contributor Author

osro commented Nov 29, 2012

Nice! 👍

@osro
Copy link
Contributor Author

osro commented Dec 2, 2012

I finally had some time to test ObjectMakerStarling. It works perfectly!

Tough, I still had to change FromTiledMap to take the entire tmx object as an argument, because I need to load those external tileset files. I also made TmxMap class to skip the external files as otherwise it creates an "empty" tileset from them.

https://github.com/osro/Citrus-Engine/commit/7302b11d68c792d62e886cb9e7ca78eb016c4a2f
https://gist.github.com/dc8e589fef58bb5cd98b

@alamboley
Copy link
Member

I've never worked with external tilesets in the editor, and I don't have tsx file to test. Have you find some tsx samples?

However when we parse the map, we should have information on the external tile sets right?

@osro
Copy link
Contributor Author

osro commented Dec 2, 2012

Yep, the main problem is that as the current ObjectMakers will create the TmxMap object and I don't have a way to add those tilesets before it process the objects.

In the Tiled editor you can export any tileset you have made to an external file.

Alt Text

And then you can import that file to other maps from menu (Map > Add External tileset)

The tileset file is XML file that is in the same format as it would be inside the TMX file.
https://github.com/bjorn/tiled/wiki/TMX-Map-Format

Here is an example from one of my files

<?xml version="1.0" encoding="UTF-8"?>
<tileset name="tilset" tilewidth="32" tileheight="32">
 <image source="../../../assets/images/tileset.png" width="64" height="128"/>
 <tile id="0">
  <properties>
   <property name="name" value="ground4"/>
  </properties>
 </tile>
 <tile id="1">
  <properties>
   <property name="name" value="ground3"/>
  </properties>
 </tile>
 <tile id="2">
  <properties>
   <property name="name" value="ground2"/>
  </properties>
 </tile>
 <tile id="3">
  <properties>
   <property name="name" value="ground1"/>
  </properties>
 </tile>
 <tile id="4">
  <properties>
   <property name="name" value="brick1"/>
  </properties>
 </tile>
</tileset>

@alamboley
Copy link
Member

Ok, I've be able to test quickly! That's cool, it exports the properties that we defined.

Then if we add our tsx as an external tile, we can't see properties. However using the button on the left import the tilesets and then we can access properties. Finally, it isn't what we need ?

@osro
Copy link
Contributor Author

osro commented Dec 2, 2012

mapeditor/tiled#242

There is some technical limitation once you have exported your tileset.
So if you want to edit the properties again, you need press the import button, make your changes and then export it again to a same file.

@alamboley
Copy link
Member

Yes indeed, but finally we can do it easily. The problem with ObjectMaker is to make it as generic as possible. And finally if we can use simple tricks to do it, that's perfect!

@alamboley
Copy link
Member

I mean, finally we just need to press the import button on our external tsx file and then it will be ok via the ObjectMaker. There is a problem using this method?

@osro
Copy link
Contributor Author

osro commented Dec 2, 2012

Nope, the tmx file will point to the external file

<?xml version="1.0" encoding="UTF-8"?>
<map version="1.0" orientation="orthogonal" width="60" height="40" tilewidth="32" tileheight="32">
 <tileset firstgid="1" source="tileset.tsx"/>
<layer name="Tile Layer 1" width="60" height="40">
... etc

@alamboley
Copy link
Member

I've make some test : indeed you have this "code" if the tileset is external, but then if you import it, it is no more external.

<tileset firstgid="121" source="../../../../../../Desktop/tiles.tsx"/>
 <layer name="background" width="20" height="10">

after import :

<tileset firstgid="121" name="tiles" tilewidth="64" tileheight="64">
  <image source="Genetica-tiles.png" trans="ff00ff" ...

And it works fine with the actual ObjectMaker

@osro
Copy link
Contributor Author

osro commented Dec 2, 2012

Yep, but then I lose the point why it's external file :D

What I have done is that I have one "template.tmx" file where I manage my external tilesets.
Now this way I can keep the other mapfiles pointing to those external files and I don't have todo the "export/import" part to all of my maps.

@alamboley
Copy link
Member

Hmm ok, I understand :)

@alamboley
Copy link
Member

Now that the ObjectMakerStarling enables the AssetManager as an argument, there shouldn't be anymore issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants