Dynamic tiled sprite

Is it possible to create a dynamic tiled sprite based on selected map?

I mean i have an obstacle in tiled sprite version and I put it on the game randomly and manually each level. Then I want that tiled sprite to change if I selected a different map design, any idea how can I achieve this one?

I Don’t think there’s a way to do this as of now. however there are plans to add tile maps to gdevelop some time soon so there may be some way to do this once it’s added maybe

So as Ninja said, there’s not a way to do this “out of the box” right now as Tiled Sprites do not allow for multiple animations.

However, there is a way to do this, but it requires a few steps:

Object and Variable Prep:

  1. Set up multiple tiled sprite objects.
  2. Ensure they have the same name except for a number. e.g. TiledDesign1, TiledDesign2, etc
  3. Make a separate object (tiled sprite or sprite) that is named TiledDesign0. This should just be a red square so you can easily see where they are.
  4. Make all of them global objects.
  5. Add them all to a object group of Tile Designs. This should also be global.
  6. Set up your maps, but use TiledDesign0.
  7. Set up a Scene Variable for each of your maps, named “MapDesign”.
  8. Set the MapDesign variable to the number that matches up with the TiledDesign you want to use. e.g. if you want to use TiledDesign1, the MapDesign scene variable should be set to 1.

Events:

  1. Set up an event with At the beginning of the scene as the condition, with the action of Hide TiledDesign0.
  2. Set up a subevent that uses the For Each Object event type.
  3. Set the object to TiledDesign0. This is letting us do actions for every instance of the TiledDesign0 you have placed on the map.
  4. Since we’re just doing this at the start of the scene, no condition is required.
  5. For your actions, you want to do Create an object from its name, select the group of Tile Designs, and set the name as “TiledDesign + ToString(Variable(MapDesign))”. This is using the number you have on the Scene Variable to generate the correct tiled sprite graphics.
  6. Set the position to TiledDesign0.X()/TiledDesign0.Y(). Select the layer to whatever you want. This will set this new tiledsprite to be the exact same start position of the TiledDesign0.
  7. In the same event, underneath the prior action, create a Modify the width of a Tiled Sprite action. Set the width to TiledDesign0.Width(), do the same with a Modify the height of a Tiled Sprite, but with TiledDesign0.Height().

You might even make all of the above events into an external event so you can just link them for each new stage. However, doing the above SHOULD mean the only thing you need to update is the Scene Variable mentioned above with a new number, and your level will have new graphics.

I want to stress should, as I’ve never done this before, but it should work in theory.

3 Likes

Hi Silver-Streak,

Thank you for the detailed steps. I just finished it just this week. And your answer is exactly the same with the solution I did on my project but I guess your answer is way more better and clean, I will try to change my project and apply this one.

Anyways, you even mentioned everything I did but with some better solution, however I did encountered a problem with changing my tile width and height, my tile is a ground and has a behavior platform, when I did changed the size of it, only the first cell covered by ground object can be run on, and after that first cell, my character will fall. To be more clearer, if I have this red box setup on my map and have a 32 by 32 cell, then I put a ground tileset to 2 cells that means width of that object = 64, and replace it with let’s say TileDesign1 and change the width and height using an action, the behavior of that object only applies on the fist cell and for the second cell my character will fall.

So the secret is that TiledDesign0 is where you put the platform behavior. All of the other objects are visual only.

So your platforms are already built out (and don’t get resized by events), but graphically hidden. Then the TiledDesign1/2/3/etc show the visuals for the platforms.

2 Likes

Oh yeah, you’re right this might be the best solution in my case. What I did on my current solution is that I added both Tileset 1 and Tileset 2 with same position, width and height, I just delete Tile set based on selected MapDesign, and it totally works with me but I don’t like that solution it’s little bit messy.

Thank you for your comment and detailed steps, this will make improve my game and less messy with my events and objects.