cocos2dx教程之CCSprite

来源:互联网 发布:directx编程入门 pdf 编辑:程序博客网 时间:2024/06/06 03:49

boolCCSprite::initWithFile(const char *pszFilename, constCCRect&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);  


原创粉丝点击