Skip to content
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

Could add setOpacity and setColor !!? #24

Open
Yehsam23 opened this issue Jul 24, 2013 · 4 comments
Open

Could add setOpacity and setColor !!? #24

Yehsam23 opened this issue Jul 24, 2013 · 4 comments

Comments

@Yehsam23
Copy link

Hi Raymond:

Could you support setOpacity & setColor function like CCNodeRGBA?
Because sometimes we need to fadein/out or tint!!

Thanks you.

@vkbsb
Copy link

vkbsb commented Jul 24, 2013

I think it's not a good idea to touch the alpha, because the animation might already deal with alpha. For tinting i have written the code which can be modified to set the alpha value as well. This works just like the replaceSprite() function.
In SuperAnimNodeV2.cpp : draw function add these lines and then the following functins.

---------------to be added to CCAnimNodeV2.cpp: draw() line Num: 517
ccV3F_C4B_T2F_Quad aOriginQuad = aSprite->mQuad;
aSprite->mQuad = sAnimObjDrawnInfo.mTransform.mMatrix * aSprite->mQuad;
ccColor4B aColor = ccc4(sAnimObjDrawnInfo.mColor.mRed, sAnimObjDrawnInfo.mColor.mGreen, sAnimObjDrawnInfo.mColor.mBlue, sAnimObjDrawnInfo.mColor.mAlpha);

    //check if the color was set for this sprite.
    SuperSpriteIdToCCColor3BMap::const_iterator colorItr = mSpriteColorMap.find(sAnimObjDrawnInfo.mSpriteId);
    if (colorItr != mSpriteColorMap.end()) {
        aColor.r = colorItr->second.r;
        aColor.g = colorItr->second.g;
        aColor.b = colorItr->second.b;
    }

////-------------------add these functions to AnimNodeV2.cpp and you have to declare them in AnimNodeV2.h
void SuperAnimNode::setSpriteColor(const std::string &theSpriteName, ccColor3B newColor)
{
SuperAnimSpriteId anOriginSpriteId = InvalidSuperAnimSpriteId;
SuperAnimSpriteId aCurSpriteId;
SuperAnimSpriteMgr::GetInstance()->BeginIterateSpriteId();
while (SuperAnimSpriteMgr::GetInstance()->IterateSpriteId(aCurSpriteId)) {
SuperAnimSprite* aSuperAnimSprite = (SuperAnimSprite*)aCurSpriteId;
std::string aSpriteFullPath = aSuperAnimSprite->mStringId;
if (aSpriteFullPath.length() >= theSpriteName.length() &&
aSpriteFullPath.substr(aSpriteFullPath.length() - theSpriteName.length()) == theSpriteName)
{
anOriginSpriteId = aCurSpriteId;
break;
}
}
if (anOriginSpriteId != InvalidSuperAnimSpriteId) {
mSpriteColorMap[anOriginSpriteId] = newColor;
}
}

void SuperAnimNode::resetSpriteColor(const std::string &theSpriteName)
{
SuperAnimSpriteId anOriginSpriteId = InvalidSuperAnimSpriteId;
SuperAnimSpriteId aCurSpriteId;
SuperAnimSpriteMgr::GetInstance()->BeginIterateSpriteId();
while (SuperAnimSpriteMgr::GetInstance()->IterateSpriteId(aCurSpriteId)) {
SuperAnimSprite* aSuperAnimSprite = (SuperAnimSprite*)aCurSpriteId;
std::string aSpriteFullPath = aSuperAnimSprite->mStringId;
if (aSpriteFullPath.length() >= theSpriteName.length() &&
aSpriteFullPath.substr(aSpriteFullPath.length() - theSpriteName.length()) == theSpriteName)
{
anOriginSpriteId = aCurSpriteId;
break;
}
}
if (anOriginSpriteId != InvalidSuperAnimSpriteId) {
SuperSpriteIdToCCColor3BMap::iterator anIter = mSpriteColorMap.find(anOriginSpriteId);
if(anIter != mSpriteColorMap.end()){
mSpriteColorMap.erase(anIter);
}
}
}

@StefanHQ
Copy link

Using alpha to fade in/out is probably one of the most essential thing to
do.

24 jul 2013 kl. 06:56 skrev vkbsb [email protected]:

I think it's not a good idea to touch the alpha, because the animation
might already deal with alpha. For tinting i have written the code which
can be modified to set the alpha value as well. This works just like the
replaceSprite() function.
In SuperAnimNodeV2.cpp : draw function add these lines and then the
following functins.

---------------to be added to CCAnimNodeV2.cpp: draw() line Num: 517
ccV3F_C4B_T2F_Quad aOriginQuad = aSprite->mQuad;
aSprite->mQuad = sAnimObjDrawnInfo.mTransform.mMatrix * aSprite->mQuad;
ccColor4B aColor = ccc4(sAnimObjDrawnInfo.mColor.mRed,
sAnimObjDrawnInfo.mColor.mGreen, sAnimObjDrawnInfo.mColor.mBlue,
sAnimObjDrawnInfo.mColor.mAlpha);

//check if the color was set for this sprite.
SuperSpriteIdToCCColor3BMap::const_iterator colorItr =

mSpriteColorMap.find(sAnimObjDrawnInfo.mSpriteId);
if (colorItr != mSpriteColorMap.end()) {
aColor.r = colorItr->second.r;
aColor.g = colorItr->second.g;
aColor.b = colorItr->second.b;
}


////-------------------add these functions to AnimNodeV2.cpp and you have
to declare them in AnimNodeV2.h
void SuperAnimNode::setSpriteColor(const std::string &theSpriteName,
ccColor3B newColor)
{
SuperAnimSpriteId anOriginSpriteId = InvalidSuperAnimSpriteId;
SuperAnimSpriteId aCurSpriteId;
SuperAnimSpriteMgr::GetInstance()->BeginIterateSpriteId();
while (SuperAnimSpriteMgr::GetInstance()->IterateSpriteId(aCurSpriteId)) {
SuperAnimSprite* aSuperAnimSprite = (SuperAnimSprite*)aCurSpriteId;
std::string aSpriteFullPath = aSuperAnimSprite->mStringId;
if (aSpriteFullPath.length() >= theSpriteName.length() &&
aSpriteFullPath.substr(aSpriteFullPath.length() - theSpriteName.length())
== theSpriteName)
{
anOriginSpriteId = aCurSpriteId;
break;
}
}
if (anOriginSpriteId != InvalidSuperAnimSpriteId) {
mSpriteColorMap[anOriginSpriteId] = newColor;
}
}

void SuperAnimNode::resetSpriteColor(const std::string &theSpriteName)
{
SuperAnimSpriteId anOriginSpriteId = InvalidSuperAnimSpriteId;
SuperAnimSpriteId aCurSpriteId;
SuperAnimSpriteMgr::GetInstance()->BeginIterateSpriteId();
while (SuperAnimSpriteMgr::GetInstance()->IterateSpriteId(aCurSpriteId)) {
SuperAnimSprite* aSuperAnimSprite = (SuperAnimSprite*)aCurSpriteId;
std::string aSpriteFullPath = aSuperAnimSprite->mStringId;
if (aSpriteFullPath.length() >= theSpriteName.length() &&
aSpriteFullPath.substr(aSpriteFullPath.length() - theSpriteName.length())
== theSpriteName)
{
anOriginSpriteId = aCurSpriteId;
break;
}
}
if (anOriginSpriteId != InvalidSuperAnimSpriteId) {
SuperSpriteIdToCCColor3BMap::iterator anIter =
mSpriteColorMap.find(anOriginSpriteId);
if(anIter != mSpriteColorMap.end()){
mSpriteColorMap.erase(anIter);
}
}
}


Reply to this email directly or view it on
GitHubhttps://github.com//issues/24#issuecomment-21462311
.

@vkbsb
Copy link

vkbsb commented Jul 24, 2013

ok if thats' what you need just add replace the alpha as well in the above
functions.

On Wed, Jul 24, 2013 at 1:39 PM, StefanHQ [email protected] wrote:

Using alpha to fade in/out is probably one of the most essential thing to
do.

24 jul 2013 kl. 06:56 skrev vkbsb [email protected]:

I think it's not a good idea to touch the alpha, because the animation
might already deal with alpha. For tinting i have written the code which
can be modified to set the alpha value as well. This works just like the
replaceSprite() function.
In SuperAnimNodeV2.cpp : draw function add these lines and then the
following functins.

---------------to be added to CCAnimNodeV2.cpp: draw() line Num: 517
ccV3F_C4B_T2F_Quad aOriginQuad = aSprite->mQuad;
aSprite->mQuad = sAnimObjDrawnInfo.mTransform.mMatrix * aSprite->mQuad;
ccColor4B aColor = ccc4(sAnimObjDrawnInfo.mColor.mRed,
sAnimObjDrawnInfo.mColor.mGreen, sAnimObjDrawnInfo.mColor.mBlue,
sAnimObjDrawnInfo.mColor.mAlpha);

//check if the color was set for this sprite.
SuperSpriteIdToCCColor3BMap::const_iterator colorItr =
mSpriteColorMap.find(sAnimObjDrawnInfo.mSpriteId);
if (colorItr != mSpriteColorMap.end()) {
aColor.r = colorItr->second.r;
aColor.g = colorItr->second.g;
aColor.b = colorItr->second.b;
}


////-------------------add these functions to AnimNodeV2.cpp and you have
to declare them in AnimNodeV2.h
void SuperAnimNode::setSpriteColor(const std::string &theSpriteName,
ccColor3B newColor)
{
SuperAnimSpriteId anOriginSpriteId = InvalidSuperAnimSpriteId;
SuperAnimSpriteId aCurSpriteId;
SuperAnimSpriteMgr::GetInstance()->BeginIterateSpriteId();
while (SuperAnimSpriteMgr::GetInstance()->IterateSpriteId(aCurSpriteId)) {
SuperAnimSprite* aSuperAnimSprite = (SuperAnimSprite*)aCurSpriteId;
std::string aSpriteFullPath = aSuperAnimSprite->mStringId;
if (aSpriteFullPath.length() >= theSpriteName.length() &&
aSpriteFullPath.substr(aSpriteFullPath.length() - theSpriteName.length())
== theSpriteName)
{
anOriginSpriteId = aCurSpriteId;
break;
}
}
if (anOriginSpriteId != InvalidSuperAnimSpriteId) {
mSpriteColorMap[anOriginSpriteId] = newColor;
}
}

void SuperAnimNode::resetSpriteColor(const std::string &theSpriteName)
{
SuperAnimSpriteId anOriginSpriteId = InvalidSuperAnimSpriteId;
SuperAnimSpriteId aCurSpriteId;
SuperAnimSpriteMgr::GetInstance()->BeginIterateSpriteId();
while (SuperAnimSpriteMgr::GetInstance()->IterateSpriteId(aCurSpriteId)) {
SuperAnimSprite* aSuperAnimSprite = (SuperAnimSprite*)aCurSpriteId;
std::string aSpriteFullPath = aSuperAnimSprite->mStringId;
if (aSpriteFullPath.length() >= theSpriteName.length() &&
aSpriteFullPath.substr(aSpriteFullPath.length() - theSpriteName.length())
== theSpriteName)
{
anOriginSpriteId = aCurSpriteId;
break;
}
}
if (anOriginSpriteId != InvalidSuperAnimSpriteId) {
SuperSpriteIdToCCColor3BMap::iterator anIter =
mSpriteColorMap.find(anOriginSpriteId);
if(anIter != mSpriteColorMap.end()){
mSpriteColorMap.erase(anIter);
}
}
}


Reply to this email directly or view it on
GitHub<
https://github.com/raymondlu/super-animation-samples/issues/24#issuecomment-21462311>

.


Reply to this email directly or view it on GitHubhttps://github.com//issues/24#issuecomment-21469646
.

@Yehsam23
Copy link
Author

CCNodeRGBA use
_displayedOpacity = _realOpacity * parentOpacity/255.0;
It use parentOpacity and self Opacity to change this frame alpha
So i think this is a good idea!!

Thanks a lot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants