[Solved] 8-Bit Bitmasking with Corner Tiles

Hello friends, I need help

I am trying to create Tile Bitmasking. link

before ====>after

  • I have created an 8bit detector that works well for one tile. MatrixDetector
  • MatrixDetector detects 8 tiles around and accordingly generates a frame number that changes the given tile at the x,y position

I have these issues

  1. After starting, I want to change each island tile using MatrixDetector, but it doesn’t work.

  2. Adding an island works correctly, it changes the tile according to the surrounding tiles / but when I want to call the MatrixDetector function on 8 surrounding tiles, it does not work

I am sending zip file game-island

I’ve tried everything, but I can’t apply it to all tiles.

island1

I’m very new to tilemapping, so take this with a grain of salt. But I believe your issue will be related more to the program you’re using for making your tilemap than to GDevelop… Having said that, I’m sure there are still people here who can probably help you.

What program are you using for tilemapping?

he did everything in Gdevelop btw. :wink:

Hi there!

You’re on the rigth track for the Corner tiles!

Well done so far! There were a lot of demands for something like that to be implemented into Gdevelop, so it’s pretty impressive how far you already got!

First a few improvements for your Gdevelop script:

When creating new events you added a “Trigger Once” in the conditions. You should to remove that, otherwise you cannot keep building tiles by dragging the mouse quickly. Since you already check in the condition if there isn’t already a tile on the position, you will already build only one tile per spot. If you want to be able to build one tile per click, I’d use the mouse button release condition instead. Or set a boolean variable, and toggle it on mouse button press and release, to build only one tile per press.

Then when you check the tile animation number of the surrounding tiles in your events, you should make sure to “pick all instances” of the island object first. Otherwise it might check only the island you just created, and not actually check the other island tiles:

Then inside your MatrixDetect extension, you used the expression
“ToString(test.Variable(matrix1))”

The standard way of writing it would be
“test.Variablestring(matrix1))”

It might still work the way you wrote it, but if I remember well, there can be instances where it messes things up, so I’d rather be safe.

Also I think you did not place all the tiles from the beginning unto the same grid raster, so you might need to recreate that, to avoid blue lines between certain tiles, or a few tile errors.

Now to why your tiles don’t change animations correctly:

The first big issue is that you didn’t name the animations correctly.
You named the animation below the animation, not above. The name of an animation is always written above it. It’s not very obvious, I give you that, but that means your animation names are off set by 1.

And also, in the tutorial you linked, I think they made a little mistake by accident:

There are only 47 tiles, not 48! (You can see that in the list where they describe which number corresponds to which tile. There are only 47) So if you look at the image they provided, you need to use tile 48 as tile 47 actually! Tile 47 is already represented by tile 1, if you compare the two!

After that is fixed, you forgot one more step in your calculations that is described in the tutorial:
You need to do a second bool check of neighbouring tiles of all the diagonal tiles. So if you have a tile on north east for example, you need to check if there is a tile to the right or below that tile as well. And if not set the bool to 0. You skipped that process in your extension so you’d need to add that!

So if you change that it should work.

Feel free to post if you made any progress as well, I’d be curious!

This message was meant for Angelo. :person_facepalming:

hmm I tried to look it up

  1. I have 47 tiles and they are all correct … they are not shifted :slight_smile:
    I used this table of 47 tiles
    5d341540187f0cc268d8cdccd3620ae11beb6213

  2. MatrixDetektor is completely fine, it also includes 2 corner checks, return only these 47 numbers :slight_smile:


Problems

the first run of the function returns the correct number of the tile, but when I call the function for the surrounding tiles 8x it returns the value of the very first tile

Pick all instances of island didn’t help

With Pick all instances of island, you can also try calling “for each island”, in order to loop through each existing tile.

I’m not sure I’ll have the time to tinker with the tile mapping until it works.

My recommendation would be, that you set it up without corner tiles first.
If there is some issue, you’ll be much more likely to find out what it is inside a simple concept, and then you can transfer it into a bigger thing. :+1:

But is the original project you shared the same as the one you’re working with?

I had a second look, you’re right not all animations were shifted.
Also you did indeed check a second time for the diagonal tiles, yes, I had overlooked that sorry.

I think you call “island” inside of the extension as if it’s the island object, whereas it’s just an instance of island, that’s where some of the mix ups happen.

Again I’d recommend to do a smaller version without corner tiles first, and build from there.

I had a similar requirement for walls that I could just place in an editor and would change depending on the surrounding walls touching the newly placed piece. I also had written an extension for it.

I’ve taken your project, and modified it to use my extension, and updated the extension to fit in with your objects. The extension has 2 functions - one for 4 way checks (horizontal and vertical), the other for 8 way (4 way plus the diagonals)

Here is a link to the updated project.

And here’s how it looks - BTW, those dots in the middle are from the sprites in the project. It’s because of the 4-way check. It’s also a mess if I used 8-way, as there are animations missing. For example, a block with neighbours at 1 & 2. There is no block with an animation value of 3.

I realise in your code you allow for this by performing some checks, but that’s a bit of a hack to get around the problem that some animations are missing. Add those animations, even if they are duplicates of other ones. It makes the whole project less messy and less prone to errors/bugs.


Islands

1 Like

EUREKA :grinning:

island-eureka

MrMen and LeakySafe , now it all works properly :smiley:

Just added Pick all instance of island in the right places.

Great job guys, thank you very much. Gdevelop is great.

2 Likes

Awesome! Glad it works now!

Hello, would you mind sharing an example of this working, I am very interested in making an example template.

Yes, I will share, this community has helped me and I hope to help others.

2 Likes