GDevelop icon indicating copy to clipboard operation
GDevelop copied to clipboard

Support for Tilemaps objects (tilesets and Tiled files)

Open blurymind opened this issue 8 years ago • 254 comments

See also the card on the roadmap on Trello

If you're interested in implementing this, read the discussion so far. In particular, there are important decisions to be made about which library to use, how to integrate this in the editor and how to ensure performance.

Thanks, @4ian

below is the original post/discussion:


With the new ide we are still missing a very important object- the tilemap. Its important because it would help reduce the memory the game is using- allowing is to make much bigger maps. The workflow of using tilesets and tilemaps is also much nicer and is a standard for 2d games.

My proposal is to allow to import tilemaps made in tiled- since that is now an open source industry/indie standard when it comes to 2d games. Most other game engines support it too (godot,defold,phaser,unity, etc) and has a wide use in the gamedev community. https://www.mapeditor.org/ https://steemit.com/gamedev/@tensaix2j/tutorial-part-6-how-to-create-a-html5-game-using-tiled-map-editor-js-and-canvas

What's great about going this way is also that we dont have to start from scratch! Since tiled is such a popular tilemap editor and file type, it already has an implementation for pixi.js and cocos https://github.com/riebel/pixi-tiledmap https://github.com/pixijs/pixi-tilemap

NPM: https://www.npmjs.com/package/pixi-tiled https://www.npmjs.com/package/pixi-tiledmap https://www.npmjs.com/package/tiled-to-pixi https://www.npmjs.com/package/tiled-utils and many more... https://www.npmjs.com/search?q=tiled%20pixi

There are also many tiled files ready to be used for testing here: https://github.com/bjorn/tiled/tree/master/examples We can even use them in example gdevelop projects :D

Tiled exports both to json and xml btw in terms of formatting- making it great for an html5 engine. http://docs.mapeditor.org/en/stable/reference/json-map-format/

example of rendering a tiled file in phaser https://phaser.io/examples/v2/loader/load-tilemap-json

So why reinvent the wheel. This will give us the basic tilemap object inside gdevelop5 plus all the perks of being able to use tiled- an editor that has smart autotiles and many advanced features that have been developed for many years. Later on we can add ability to create and author the tilemaps inside the newIde - but with laid groundwork for how these objects are structured and the perk of having support for this industry standard

There is a bounty on this feature https://www.bountysource.com/issues/58876395-support-for-tilemaps-objects-tilesets-and-tiled-files

EDIT: 2 years later the starter of this issue ticket learned javascript and implemented it himself. Pr still pending of course :)

image

PR here: https://github.com/4ian/GDevelop/pull/1901

blurymind avatar May 26 '18 19:05 blurymind

found this repository, which could also be useful https://github.com/kittykatattack/tileUtilities

blurymind avatar Jun 10 '18 20:06 blurymind

Hey 👋 I've put this issue on the roadmap (so that anyone can vote for it!) there: https://trello.com/c/vJacNvXq/65-support-for-tilemaps-objects-gdevelop-5-html5-games

I'm closing this issue as open issues on Github is now be dedicated to bugs only :) (But it's still possible to continue the discussion on this issue even if it's closed)

4ian avatar Jul 17 '18 21:07 4ian

there is a cool html5 tilemap editor here: https://github.com/less-xx/tile-map-editor but unfortunately it can not import tiled files (xml or json) it does both standard and isometric maps.

One thing that I would like to see improved upon gdevelop4 is having the tilemap editing happen inside the scene editor and not as a separate window. I found that to be a bit inconvenient in the implementation of tilemaps in gd4

blurymind avatar Nov 26 '18 12:11 blurymind

The developers of rpg maker mv have actually contributed a tilemap renderer to pixi.js and it is an officially in the pixi git: https://github.com/pixijs/pixi-tilemap

A potential problem of using it would be any imposed limitations/dependencies from rpg maker mv. At least for now it looks maintained - with the last update being a week ago. Rpg maker mv does have a huge userbase

blurymind avatar Nov 26 '18 12:11 blurymind

pixi-tilemap could be interesting. Ideally we can find something that is well maintained, or at least with an implementation that have a good quality. Two things that may not be handled and so we'll have to check how to do it is:

  • Collision handling.
  • For really huge tilemap, we would ideally avoid to render all tiles if they are not displayed on screen.

4ian avatar Nov 26 '18 13:11 4ian

Zero time to work on this one, but for tiles we can store a lot of sprites in a common PIXI container or a particles container for more speed. Then always hide all the sprites/tiles but leave visible the ones in front of the camera. For extra performance, it should be possible to store the tiles in a 2D array, and map the camera top-left and bottom-right points into array indices. I did something like this in python years ago.

Also, because the permissive PIXI rendering system we can use arbitrary Z-orders for each layer in the same tilemap. I mean we can create a tilemap object with three layers, and put one layer at Z-index = -1, other at Z-index = 0 and the other at Z = 100 (instead of creating three different tilemap objects).

Finally, I like the in-scene object editors idea, An object editor should be able to define custom panels on the editor, and instances should handle clicks, drags, end clicks, etc. A lot of work but a nice long-term goal.

Lizard-13 avatar Nov 26 '18 17:11 Lizard-13

Finally, I like the in-scene object editors idea, An object editor should be able to define custom panels on the editor, and instances should handle clicks, drags, end clicks, etc.

Yep, I think it's fair :) Ideally we would have an easy to use API (not too large/not too permissive) to allow edition from the scene editor.

4ian avatar Nov 26 '18 17:11 4ian

I was trying to build a new gdevelop demo from a free set that is on itch.io - for the showreel video. But realized that the character sprites and map elements are all on tilesets. https://ansimuz.itch.io/sunnyland-woods

This made me realize how limited we are when not having this in the editor. One way this can be tackled in a lower hanging fruit kind of a way is to simply add the ability to set a visible area of a sprite object. That way what I can do from there is add a tileset importer that imports the tileset as a single resource, adds it to a number of frames, then on each frame sets the visible square area. This is how godot does both tilesets and animated sprites btw.

If the game engine side supports setting a square visible area for sprites, I can start working on adding a tileset import/cutter and a mask visible area editor to the newIDE as a first stepping stone.

blurymind avatar Dec 15 '18 12:12 blurymind

@4ian we can reuse the functionality of the collision masking editor to set visible area of a sprite inside a tileset. see for example how godot does this in that way, but with an area rect https://www.gamefromscratch.com/post/2015/04/28/Godot-Engine-Tutorial-Part-8-Tilemaps.aspx

If gdevelop.js allows that for sprite resources, I can create an importer for the newIde that generates the masks automatically or generates area rects. An area rect is basically just x1,y1,x2,y2

We could from there on make it so that for example the collision masking editor could optionally just let you use the visible area mask as collision bounds as well.

blurymind avatar Dec 15 '18 12:12 blurymind

Edit hitboxes can be repurposed to edit visible areas and expanded to be used to set the areas of a tileset like this: capture in the example I am setting the visible area of frame#1

by default the visible area could be the bounds of the image,unless the image is a tileset. In that case the visible area can be generated by the importer code, which sliced it

blurymind avatar Dec 15 '18 12:12 blurymind

To me this seems closely related to spritesheets which are also missing from GD5. Maybe this can be implemented so both tileset and spritesheets are added.

zatsme avatar Dec 15 '18 13:12 zatsme

I think this will be the best way to do it if we are to reuse whats already in gd5's ide.

The hitbox editor's UI can be improved too - I would like to give it more area for showing bigger images, add zoom in/out/pan.

blurymind avatar Dec 15 '18 13:12 blurymind

The hitbox editor's UI can be improved too - I would like to give it more area for showing bigger images, add zoom in/out/pan.

Yep, that's something that is asked for a lot: https://trello.com/c/kPRc19zV/147-add-support-for-zooming-in-out-when-editing-points-hit-boxes-or-in-a-preview-of-a-sprite-in-the-sprite-editor

Feel free to give it a try :)

For using spritesheets, Pixi.js supports setting a frame/area on the texture that is displayed - this is I think the "official" Pixi.js way of using spritesheet so that would make sense to expose it in GD.

If gdevelop.js allows that for sprite resources, I can create an importer for the newIde that generates the masks automatically or generates area rects. An area rect is basically just x1,y1,x2,y2

I'm not sure how it would work, do we really need a new "Sprite Resource"? Resource should represents "physical" files that the game rely on. So a Spritesheet would be one resource (an image, like other textures), even if we can have editors to ease the selection of the areas in the spritesheets :)

4ian avatar Dec 15 '18 14:12 4ian

This being said, both features of spritesheet and tileset/tilemap are relatively independent. They are in two different cards by the way on the roadmap: https://trello.com/c/dmElE214/103-support-for-spritesheet-textures https://trello.com/c/vJacNvXq/65-support-for-tilemaps-objects-tilesets-and-tiled-files-gdevelop-5-html5-games

From what I can see, people are more asking for now for tilemaps - so this would be for now a more impactful addition to GDevelop.

4ian avatar Dec 15 '18 14:12 4ian

@4ian I need to have the pixijs functionality somehow exposed to the engine right? I mean once a visible area is set in the editor, the engine itself needs to respect that too

I think that we dont need new type of resource, just the ability for the current game objects to have a visible area mask

blurymind avatar Dec 15 '18 14:12 blurymind

I mean once a visible area is set in the editor, the engine itself needs to respect that too

Yes of course :) This is at which point you should inspect how gdjs.SpriteRuntimeObject is done to see how images are used and in particular gdjs.SpriteRuntimeObjectPixiRenderer which is responsible for creating and updating the PIXI.Sprite of the object. This is where support for displaying some area of an image should be added. For now, images are loaded using gdjs.SpriteRuntimeObjectPixiRenderer.getAnimationFrame from the image manager, but without any information about area.

I think that we dont need new type of resource, just the ability for the current game objects to have a visible area mask

Yes. Though I've just seen in Pixi.js that there is a PIXI.SpriteSheet that is a helper class that can be given a JSON (see http://pixijs.download/dev/docs/PIXI.Spritesheet.html) and load all the textures from the spritesheet (using the same base texture, i.e, the same image file): https://github.com/pixijs/pixi.js/blob/dev/src/core/textures/Spritesheet.js#L238

So maybe you were right when speaking about resources, every sprite in a spritesheet could be a different resource (we could enhance ImageResource to have not only the file, like now, but also the area). Ideally we would support importing json from TexturePacker, Shoebox or Spritesheet.js like PIXI.SpriteSheet. This could be a tool that open the JSON and create the associated resources.

If we do this, we still need to study if this will work with other objects (i.e: will a ImageResource with an area work for a TiledSprite/PanelSprite?).

4ian avatar Dec 15 '18 16:12 4ian

Interesting, the pixi spritesheet object supports loading the mask data from a json file. Thiswill be particularly useful when we want to load it from something like texturepacker

See example: atlasExample.zip

blurymind avatar Dec 15 '18 19:12 blurymind

Another thing I could do to approach this is to add something like https://www.npmjs.com/package/unpack-texturepacker to the editor - to allow unpacking atlases and spritesheets

and https://www.npmjs.com/package/tileset-slicer

slicing a tileset into files has two downsides:

  • you are de-optimising the game
  • you are creating more files

It will be the easiest way to approach importing tilesets with no need to touch the engine- just the editor

I can add this as a command to the resourcemanager if you are interested :)

blurymind avatar Dec 15 '18 19:12 blurymind

Please do it as fast as possible..... It would be amazing.....

HarshRajSinghania avatar Jun 16 '19 15:06 HarshRajSinghania

I am going to come in and say this is a feature I really need. Linked here is a 64bit version (Linux and Windows) of the game I've been working on in Construct 2, and I would love to be developing it in GDevelop, or even then if I end up finishing it in C2, I'd eventually like to do all my projects in GDevelop, as it's easier to keep up with.

In order for this whole system to work, I have about 5 layers of active graphics, 1 that is invisible, the bottom being the water, the topmost being anything above the player, and other layers for ground, type, and solids. Plus another for the player themselves.

I hope to see tilemap support, including painting, implemented. IF IT CAN BE DONE LIKE RPG MAKER where the main tile is your bg fill (water, for example) and you select a grass icon, and it automatically uses the 9 tiles like system to fill the edges, that would be even better.

https://drive.google.com/open?id=1LYlSTF-t2ncgbQYKD2PrzV8aWjba6ufq

roracle avatar Sep 06 '19 16:09 roracle