cocos2dx教程之CCSprite

boolCCSprite::initWithFile(const char *pszFilename, const CCRect&rect)

{

   CCAssert(pszFilename != NULL, "");

   CCTexture2D *pTexture =CCTextureCache::sharedTextureCache()->addImage(pszFilename);

   if (pTexture)

   {returninitWithTexture(pTexture,rect);

   }

return false;

}

boolCCSprite::initWithSpriteFrameName(const char *pszSpriteFrameName)

{

   CCAssert(pszSpriteFrameName != NULL, "");

   CCSpriteFrame *pFrame =

            CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(pszSpriteFrameName);

   return initWithSpriteFrame(pFrame);

}


CCSpritepSprite = CCSprite::spriteWithFile("grossini.png");  

        CC_BREAK_IF(! pSprite);  

        CCSize  size = CCDirector::sharedDirector()->getWinSize();  

        // Place the sprite on the center of the screen  

        pSprite->setPosition(ccp(size.width/2, size.height/2));  

        // Add the sprite to HelloWorld layer as a child layer.  

        this->addChild(pSprite, 0);  


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章