Tix Lo lightning extension
Posts 26
Added by Tix Lo over 1 year ago

Dear Sirs,

I port the lightning source to cocos2d-x platform according to http://www.cocos2d-iphone.org/forum/topic/370/page/2

the lightning implementation is by using glVertexPointer, and so it looks like a little simple.

Maybe someone will need or improve them to more like the lightning effect.

CCLightning.h (1.6 kB)

CCLightning.cpp (5.5 kB)

HelloWorldScene.h (764 Bytes)

HelloWorldScene.cpp (2.8 kB)

Zhe Wang RE: lightning extension
Posts 1642
Location Amoy, China
Added by Zhe Wang over 1 year ago

Cool!

Enjoy Coding, Enjoy Life.

nuwan nara RE: lightning extension
Posts 19
Added by nuwan nara over 1 year ago

yep.. nice work... but i couldn't use it.. coz it gives me a compiler error.. on

CCLightning* CCLightning::lightningWithStrikePoint(CCPoint strikePoint)
{
    CCLightning* lightning = new CCLightning();     >>>>>>>>>>>error: allocating an object of abstract class type 'CCLightning' 
    if (lightning && lightning->initWithStrikePoint(strikePoint))
    {
        lightning->autorelease();
        return lightning;
    }
    CC_SAFE_DELETE(lightning);
    return NULL;
}

CCLightning* CCLightning::lightningWithStrikePoint(CCPoint strikePoint,CCPoint strikePoint2)
{
    CCLightning* lightning = new CCLightning();  >>>>>>>>>>>error: allocating an object of abstract class type 'CCLightning' 
    if (lightning && lightning->initWithStrikePoint(strikePoint,strikePoint2))
    {
        lightning->autorelease();
        return lightning;
    }
    CC_SAFE_DELETE(lightning);
    return NULL;
}

error: allocating an object of abstract class type 'CCLightning'

Tix Lo RE: lightning extension
Posts 26
Added by Tix Lo over 1 year ago

sorry, I missed something and will fix it tomorrow

nuwan nara RE: lightning extension
Posts 19
Added by nuwan nara over 1 year ago

No worries mate.. looking fwd it to... :)

Dany Menko RE: lightning extension
Posts 94
Added by Dany Menko over 1 year ago

This is amazing! You just gave me so many ideas for amazing games I could do!

Tix Lo RE: lightning extension
Posts 26
Added by Tix Lo over 1 year ago

Hi,

I checked the source again and found they work fine. Because CCLightning inherited CCRGBAProtocol, it had to
implement the four functions in CCRGBAProtocol class.

virtual void setColor(const ccColor3B& color) = 0;
virtual const ccColor3B& getColor(void) = 0;
virtual GLubyte getOpacity(void) = 0;
virtual void setOpacity(GLubyte opacity) = 0;

CCLightning implemented them, too.

CCLightning.h
CC_PROPERTY(GLubyte, m_opacity, Opacity)
CC_PROPERTY_PASS_BY_REF(ccColor3B, m_tColor, Color);

CCLightning.cpp
GLubyte CCLightning::getOpacity(void) {
return m_opacity;
}

void CCLightning::setOpacity(GLubyte opacity)
{
m_opacity = opacity;
}
const ccColor3B& CCLightning::getColor(void)
{
return m_tColor;
}
void CCLightning::setColor(const ccColor3B& color3)
{
m_tColor = color3;
}

There is a compiling error if those virtual functions are wrong. Could you check the files you downloaded again?
If anything wrong, please tell me.

best regards.

nuwan nara wrote:

yep.. nice work... but i couldn't use it.. coz it gives me a compiler error.. on

[...]

error: allocating an object of abstract class type 'CCLightning'

winipcfg winipcfg RE: lightning extension
Posts 56
Added by winipcfg winipcfg over 1 year ago

I use Microsoft Visual Studio. The behavior of compiler may be somehow different so you may not reproduce the issue.

1>cclightning.h : warning C4819: The file contains a character that cannot be represented in the current code page (950). Save the file in Unicode format to prevent data loss
1>cclightning.cpp(19): error C2057: expected constant expression
1>cclightning.cpp(19): error C2466: cannot allocate an array of constant size 0
1>cclightning.cpp(19): error C2133: 'vertices' : unknown size
1>cclightning.cpp(22): warning C4018: '<' : signed/unsigned mismatch
1>cclightning.cpp(74): warning C4244: '+=' : conversion from 'double' to 'float', possible loss of data
1>cclightning.cpp(76): warning C4244: '+=' : conversion from 'double' to 'float', possible loss of data
1>cclightning.cpp(106): error C2259: 'cocos2d::CCLightning' : cannot instantiate abstract class
1>          due to following members:
1>          'void cocos2d::CCRGBAProtocol::setIsOpacityModifyRGB(bool)' : is abstract
1>          d:\projects\library\cocos2d-1.0.1-x-0.11.0\cocos2dx\include\ccprotocols.h(66) : see declaration of 'cocos2d::CCRGBAProtocol::setIsOpacityModifyRGB'
1>          'bool cocos2d::CCRGBAProtocol::getIsOpacityModifyRGB(void)' : is abstract
1>          d:\projects\library\cocos2d-1.0.1-x-0.11.0\cocos2dx\include\ccprotocols.h(71) : see declaration of 'cocos2d::CCRGBAProtocol::getIsOpacityModifyRGB'
1>cclightning.cpp(118): error C2259: 'cocos2d::CCLightning' : cannot instantiate abstract class
1>          due to following members:
1>          'void cocos2d::CCRGBAProtocol::setIsOpacityModifyRGB(bool)' : is abstract
1>          d:\projects\library\cocos2d-1.0.1-x-0.11.0\cocos2dx\include\ccprotocols.h(66) : see declaration of 'cocos2d::CCRGBAProtocol::setIsOpacityModifyRGB'
1>          'bool cocos2d::CCRGBAProtocol::getIsOpacityModifyRGB(void)' : is abstract
1>          d:\projects\library\cocos2d-1.0.1-x-0.11.0\cocos2dx\include\ccprotocols.h(71) : see declaration of 'cocos2d::CCRGBAProtocol::getIsOpacityModifyRGB'
Angus Comrie RE: lightning extension
Posts 17
Added by Angus Comrie over 1 year ago

There are actually 6 functions the CRGBA protocol requires. If your class has no children, you can simply use something like

//CCRGBAProtocol
    CC_SYNTHESIZE(GLubyte, m_cOpacity, Opacity); 
    CC_SYNTHESIZE_PASS_BY_REF(ccColor3B, m_tColor, Color);
    CC_SYNTHESIZE(bool, m_bIsOpacityModifyRGB, IsOpacityModifyRGB);

However, if your class has children (eg, a layer or a control or something like that), then you need to also pass through the colours to children.

Normally, it follows this sort of method:

//CRGBA protocol
void CCControl::setColor(const ccColor3B& color)
{
    m_tColor=color;
    CCObject* child;
    CCArray* children=getChildren();
    CCARRAY_FOREACH(children, child)
    {
        CCRGBAProtocol* pNode = dynamic_cast<CCRGBAProtocol*>(child);        
        if (pNode)
        {
            pNode->setColor(m_tColor);
        }
    }
}

const ccColor3B& CCControl::getColor(void)
{
    return m_tColor;
}

void CCControl::setOpacity(GLubyte opacity)
{
    m_cOpacity = opacity;

    CCObject* child;
    CCArray* children=getChildren();
    CCARRAY_FOREACH(children, child)
    {
        CCRGBAProtocol* pNode = dynamic_cast<CCRGBAProtocol*>(child);        
        if (pNode)
        {
            pNode->setOpacity(opacity);
        }
    }

}

GLubyte CCControl::getOpacity()
{
    return m_cOpacity;
}

void CCControl::setIsOpacityModifyRGB(bool opacityModifyRGB)
{
    m_bIsOpacityModifyRGB=opacityModifyRGB;
        CCObject* child;
    CCArray* children=getChildren();
    CCARRAY_FOREACH(children, child)
    {
        CCRGBAProtocol* pNode = dynamic_cast<CCRGBAProtocol*>(child);        
        if (pNode)
        {
            pNode->setIsOpacityModifyRGB(opacityModifyRGB);
        }
    }
}

bool CCControl::getIsOpacityModifyRGB()
{
    return m_bIsOpacityModifyRGB;
}
Ivan Fedorov RE: lightning extension
Posts 14
Location Ukraine
Added by Ivan Fedorov 3 months ago

do not work
I fix few places for run this, but do not saw Lightning

it just was for opengl 1


(1-9/9)