// new image from png file
CCImage* img = new CCImage();
img->initWithImageFile( "2.png");

// new texture from image
CCTexture2D* tex = new CCTexture2D();
tex->initWithImage( img );

// create sprite

m_pSpr = CCSprite::create();
m_pSpr->setPosition( ccp( 100, 100 ) );
this->addChild( m_pSpr );

m_pSpr->setTexture( tex );

    this is only ccimage to ccsprite  but i want to get sprite to ccimage.
    how to do

 m_pSpr = CCSprite::create("2.png");
    m_pSpr->setPosition( ccp( 100, 100 ) );
    this->addChild( m_pSpr );

       CCImage* img = new CCImage();
        img->initWithImageFile( "m_pSpr getname");

最佳答案

试试这个。

    // sprite is the CCSprite object.
    CCRenderTexture* r = CCRenderTexture::create(sprite->getTexture()->getPixelsWide(), sprite->getTexture()->getPixelsHigh());

    r->beginWithClear(1, 1, 1, 0);
    sprite->visit();
    r->end();

    CCImage *testImage = r->newCCImage();

关于c++ - 如何将ccsprite转换为ccimage cocos2dx,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27796660/

10-11 20:01