New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It is invalid for TMXTiledMap to "setOpacity" and "setColor" #9162

Open
chengstory opened this Issue Nov 19, 2014 · 12 comments

Comments

Projects
None yet
6 participants
@chengstory
Contributor

chengstory commented Nov 19, 2014

TMXTiledMap *map = TMXTiledMap::create("Default/defaultMap.tmx");
map->setPosition(_contentSize.width / 2, _contentSize.height / 2);
map->setOpacity(80);
map->setColor(Color3B(255, 0, 189));
this->addChild(map);
1

@chengstory

This comment has been minimized.

Show comment
Hide comment
@chengstory

chengstory Nov 19, 2014

Contributor

@minggo Please take a look.

Contributor

chengstory commented Nov 19, 2014

@minggo Please take a look.

@minggo

This comment has been minimized.

Show comment
Hide comment
@minggo

minggo Nov 19, 2014

Contributor

Please give these informations:

  • engine version
  • what platform did you test on
Contributor

minggo commented Nov 19, 2014

Please give these informations:

  • engine version
  • what platform did you test on
@chengstory

This comment has been minimized.

Show comment
Hide comment
@chengstory

chengstory Nov 21, 2014

Contributor

Based on cocos2dx 3.3rc0
Window 7, Mac

Contributor

chengstory commented Nov 21, 2014

Based on cocos2dx 3.3rc0
Window 7, Mac

@minggo minggo assigned ghost Nov 21, 2014

@minggo

This comment has been minimized.

Show comment
Hide comment
@minggo

minggo Nov 21, 2014

Contributor

@huangshiwu
Please take a look.

Contributor

minggo commented Nov 21, 2014

@huangshiwu
Please take a look.

@chengstory

This comment has been minimized.

Show comment
Hide comment
@chengstory

chengstory Nov 24, 2014

Contributor

@minggo @huangshiwu Particle also have the same problem. Thanks

Contributor

chengstory commented Nov 24, 2014

@minggo @huangshiwu Particle also have the same problem. Thanks

@minggo minggo modified the milestones: v3.3, v3.3rc1 Nov 24, 2014

@minggo

This comment has been minimized.

Show comment
Hide comment
@minggo

minggo Nov 24, 2014

Contributor

I don't think it is a bug.
Can not change opacity and color for a tile map.

Contributor

minggo commented Nov 24, 2014

I don't think it is a bug.
Can not change opacity and color for a tile map.

@minggo

This comment has been minimized.

Show comment
Hide comment
@minggo

minggo Nov 24, 2014

Contributor

@ricardoquesada
What's your opinion?

Contributor

minggo commented Nov 24, 2014

@ricardoquesada
What's your opinion?

@ricardoquesada

This comment has been minimized.

Show comment
Hide comment
@ricardoquesada

ricardoquesada Nov 26, 2014

Contributor

it could be a minor bug I guess. I think Tiled allows you set the opacity of the maps (although I could be wrong). If so, then looks like a bug since users might expect to set the opacity programmatically as well.

But for sure this should not be fixed for v3.3rc1. All the tilemap fixes and improvements must be fixed for v3.4.

Contributor

ricardoquesada commented Nov 26, 2014

it could be a minor bug I guess. I think Tiled allows you set the opacity of the maps (although I could be wrong). If so, then looks like a bug since users might expect to set the opacity programmatically as well.

But for sure this should not be fixed for v3.3rc1. All the tilemap fixes and improvements must be fixed for v3.4.

@minggo minggo removed this from the v3.3rc1 milestone Nov 26, 2014

@minggo

This comment has been minimized.

Show comment
Hide comment
@minggo

minggo Nov 26, 2014

Contributor

Yep, Tiled allows to set opacity and color.

I have removed the version.

Contributor

minggo commented Nov 26, 2014

Yep, Tiled allows to set opacity and color.

I have removed the version.

@PeqNP

This comment has been minimized.

Show comment
Hide comment
@PeqNP

PeqNP Mar 1, 2015

I'm still not seeing this feature in v3.4. Is it possible I'm using the API incorrectly?

The code below still shows 255 opacity:

        tileMap = cc.TMXTiledMap:create("level01-shadow.tmx")
        tileMap:setOpacity(80)

I really need this feature, so I may see what I can do to add it.

Thanks all!

PeqNP commented Mar 1, 2015

I'm still not seeing this feature in v3.4. Is it possible I'm using the API incorrectly?

The code below still shows 255 opacity:

        tileMap = cc.TMXTiledMap:create("level01-shadow.tmx")
        tileMap:setOpacity(80)

I really need this feature, so I may see what I can do to add it.

Thanks all!

@PeqNP PeqNP unassigned ghost Mar 1, 2015

@PeqNP

This comment has been minimized.

Show comment
Hide comment
@PeqNP

PeqNP Mar 2, 2015

I'm not really comfortable making a pull request for this because I feel that my approach is a bit of a hack. Here is the code, which I may create a pull request for, depending on what you guys think. I feel that there is a better way to do this.

// file: 2d/CCTMXLayer.cpp
void TMXLayer::setOpacity(GLubyte opacity)
{
    for (int y=0; y < _layerSize.height; y++)
    {
        for (int x=0; x < _layerSize.width; x++)
        {
            Vec2 p = Vec2(x, y);
            Sprite *sp = getTileAt(p);
            sp->setOpacity(opacity);
        }
    }

    // Must be done to avoid layer resetting back to black.
    Node::setOpacity(opacity);
}

I had issues iterating over the _children variable. I'm sure it's because of my misunderstanding with C++. This is my first time writing in it. Also, you'll need to declare the setOpacity method virtual in the CCTMXLayer.h header file.

I also found that doing it this way forces you to set the opacity much higher than it needs to be to achieve the desired effect. I'm assuming it's because the parent's opacity is adding to the child's opacity. For instance, I now have to set the opacity to ~170 to get about 80 opacity.

PeqNP commented Mar 2, 2015

I'm not really comfortable making a pull request for this because I feel that my approach is a bit of a hack. Here is the code, which I may create a pull request for, depending on what you guys think. I feel that there is a better way to do this.

// file: 2d/CCTMXLayer.cpp
void TMXLayer::setOpacity(GLubyte opacity)
{
    for (int y=0; y < _layerSize.height; y++)
    {
        for (int x=0; x < _layerSize.width; x++)
        {
            Vec2 p = Vec2(x, y);
            Sprite *sp = getTileAt(p);
            sp->setOpacity(opacity);
        }
    }

    // Must be done to avoid layer resetting back to black.
    Node::setOpacity(opacity);
}

I had issues iterating over the _children variable. I'm sure it's because of my misunderstanding with C++. This is my first time writing in it. Also, you'll need to declare the setOpacity method virtual in the CCTMXLayer.h header file.

I also found that doing it this way forces you to set the opacity much higher than it needs to be to achieve the desired effect. I'm assuming it's because the parent's opacity is adding to the child's opacity. For instance, I now have to set the opacity to ~170 to get about 80 opacity.

kama2vern added a commit to kama2vern/solno that referenced this issue Mar 4, 2015

@walzer walzer added this to the unplanned milestone Apr 27, 2015

@walzer walzer added the type:bug label Apr 27, 2015

@minggo minggo removed this from the unplanned milestone Aug 19, 2016

@slackmoehrle

This comment has been minimized.

Show comment
Hide comment
@slackmoehrle

slackmoehrle Nov 27, 2017

Contributor

There are still some issues, possibly related this, that our users are experiencing. From the U.S forums:

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);
Contributor

slackmoehrle commented Nov 27, 2017

There are still some issues, possibly related this, that our users are experiencing. From the U.S forums:

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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment