TMXTiledMap and setOpacity

TMXTiledMap and setOpacity
0.0 0

#1

I have a TMXTiledMap and I’m trying to change its opacity but it won’t work.
Here is my code:

auto mapBackground = TMXTiledMap::create(mapName+".tmx");
mapBackground->setOpacity(50);
this->addChild(mapBackground);

Any help would be appreciated.


#2

I did some searching and I found this. It says that it was filed as a bug but never said whether or not it was fixed so I’m assuming it wasn’t cause I still have the problem.


#3

I will ask the engineering team for an update on this issue.


#4

Thank you.


#5

At this point, it has not been fixed. I have updated the issue with your feedback.


#6

It has been a few months and I was wondering if there has been any updates on the issue.


#7

I don’t think it has. I can ask again for an update.


#8

@xxYxx I think you can change the opacity of each layer. so in such case that you want to set it to all layers just iterate through all of them and set opacity. can be a quick workaround for you.


#9

I thought about this. It may work as desired!


#10

I just tried changing the opacity of a layer and it does not work. However, this gave me the idea of trying just one tile which works. However, this feels extremely inefficient so I still believe that it should be fixed.


#11

are you using Tiled to create the TMX ?

If you do, there is an option to set opacity for each layer in the tiled setup (not via code). did you try to see if setting it there works?

If it does work, I assume you may doing something wrong. but if it doesn’t it sound definitely like an issue.


#12

I am using Tiled and for my TMX files and I can change the opacity in Tiled.
In case I am doing something wrong, this is how I’m changing the opacity in code

mapBackground->getLayer("map")->setOpacity(50);

#13

This is the logical way of doing it. TileMap can have many layers(Object Layer, SpriteLayer, tile layer) so if you try to do

It should not reduce opacity of whole object which is logically correct. What if developer only wants to reduce opacity of Object Layer or tile layer and keep the rest to default? and if one wants to modify whole map opacity then they should loop around the layers and set them individually, giving developers more flexibility in managing their layers.


#14

@Lazy_Gamer he just said that applying to a layer doesn’t work. I did it as well now and I also can say it doesn’t work on my end.

@xxYxx you can try to look into the code and see how the TMXTiledMap is doing so. it may be that when he creates each tile it set its opacity.

Anyway, you can just inherit TMXTiledMap and override SetOpacitiy which will do just that. go over each tile and set its opacity.


#15

I had not considered that. Lets try this.