Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon

Using the Tiled map editor

Save for later
  • 5 min read
  • 13 Oct 2015

article-image

LibGDX is a game framework and not a game engine. This is why it doesn't have any editor to place the game objects or to make levels. Tiled is a 2D level/map editor well-suited for this purpose. In this article by Indraneel Potnis, the author of LibGDX Cross-platform Development Blueprints, we will learn how to draw objects and create animations. LibGDX has an excellent support for rendering and reading maps/levels made through Tiled.

(For more resources related to this topic, see here.)

Drawing objects

Sometimes, simple tiles may not satisfy your requirements. You might need to create objects with complex shapes. You can define these shape outlines in the editor easily. The first thing you need to do is create an object layer. Go to Layer | Add Object Layer:

using-tiled-map-editor-img-0

You will notice that a new layer has been added to the Layers pane called Object Layer 1. You can rename it if you like:

using-tiled-map-editor-img-1

With this layer selected, you can see the object toolbar getting enabled:

using-tiled-map-editor-img-2

You can draw basic shapes, such as a rectangle or an ellipse/circle:

using-tiled-map-editor-img-3

You can also draw a polygon and a polyline by selecting the appropriate options from the toolbar. Once you have added all the edges, click on the right mouse button to stop drawing the current object:

using-tiled-map-editor-img-4

Once the polygon/polyline is drawn, you can edit it by selecting the Edit Polygons option from the toolbar:

using-tiled-map-editor-img-5

After this, select the area that encompasses your polygon in order to change to the edit mode. You can edit your polygons/polylines now:

using-tiled-map-editor-img-6

You can also add custom properties to your polygons by right-clicking on them and selecting Object Properties:

using-tiled-map-editor-img-7

You can then add custom properties as mentioned previously:

using-tiled-map-editor-img-8

You can also add tiles as an object. Click on the Insert Tile icon in the toolbar:

using-tiled-map-editor-img-9

Once you select this, you can insert tiles as objects into the map. You will observe that the tiles can be placed anywhere now, irrespective of the grid boundaries:

using-tiled-map-editor-img-10

To select and move multiple objects, you can select the Select Objects option from the toolbar:

using-tiled-map-editor-img-11

You can then select the area that encompasses the objects. Once they are selected, you can move them by dragging them with your mouse cursor:

using-tiled-map-editor-img-12

You can also rotate the object by dragging the indicators at the corners after they are selected:

Unlock access to the largest independent learning library in Tech for FREE!
Get unlimited access to 7500+ expert-authored eBooks and video courses covering every tech area you can think of.
Renews at £16.99/month. Cancel anytime

using-tiled-map-editor-img-13

Tile animations and images

Tiled allows you to create animations in the editor. Let's make an animated shining crystal. First, we will need an animation sheet of the crystal. I am using this one, which is 16 x 16 pixels per crystal:

using-tiled-map-editor-img-14

The next thing we need to do is add this sheet as a tileset to the editor and name it crystals. After you add the tileset, you can see a new tab in the Tilesets pane:

using-tiled-map-editor-img-15

Go to View | Tile Animation Editor to open the animation editor:

using-tiled-map-editor-img-16

A new window will open that will allow you to edit the animations:

using-tiled-map-editor-img-17

On the right-hand side, you will see the individual animation frames that make up the animation. This is the animation tileset, which we added. Hold Ctrl on your keyboard, and select all of them with your mouse. Then, drag them to the left window:

using-tiled-map-editor-img-18

The numbers beside the images indicate the amount of time each image will be displayed in milliseconds. The images are displayed in this order and repeat continuously. In this example, every image will be shown for 100ms or 1/10th of a second. In the bottom-left corner, you can preview the animation you just created. Click on the Close button.

You can now see something like this in the Tilesets pane:

using-tiled-map-editor-img-19

The first tile represents the animation, which we just created. Select it, and you can draw the animation anywhere in the map. You can see the animation playing within the map:

using-tiled-map-editor-img-20

Lastly, we can also add images to our map. To use them, we need to add an image layer to our map. Go to Layer | Add Image Layer. You will notice that a new layer has been added to the Layers pane. Rename it House:

using-tiled-map-editor-img-21

To use an image, we need to set the image's path as a property for this layer. In the Properties pane, you will find a property called Image. There is a file picker next to it where you can select the image you want:

using-tiled-map-editor-img-22

Once you set the image, you can use it to draw on the map:

 using-tiled-map-editor-img-23

Summary

In this article, we learned about a tool called Tiled, and we also learned how to draw various objects and make tile animations and add images.

Carry on with LibGDX Cross-platform Development Blueprints to learn how to develop great games, such as Monty Hall Simulation, Whack a Mole, Bounce the Ball, and many more.

You can also take a look at the vast array of LibGDX titles from Packt Publishing, a few among these are as follows:

Resources for Article:

 


Further resources on this subject: