游戏要用动画,美工还没做出来,于是,从网上找来了几张图,不过图是JavaME时代的图,动画都是靠裁切来显示的,于是想将大图分割成小图来用。
图片规格:图中每个小图的大小是相等的,基本上都是正行,整列的。
上代码:
const char * CutNormalImage::IMAGE_FORMAT_NAME = "image_ (%d).png" ; const char * pSaveImageFromar = "image_%d_%d_%d.png" ; int row = 4 ; int col = 4 ; int begin = 1 ; int end = 116 ; USING_NS_CC ; void CutNormalImage::cutImage() { for (int k = begin ;k <= end ; k++) { const char * pImageName = CCString::createWithFormat(CutNormalImage::IMAGE_FORMAT_NAME,k)->getCString() ; CCSprite* pSprite = CCSprite::create(pImageName); pSprite->setAnchorPoint(ccp(0,0)); float width = pSprite->getContentSize().width / col ; float height = pSprite->getContentSize().height / row ; for (int i = 0 ; i < row ;i++) { for (int j = 0 ;j < col ;j++) { float x = j * width ; float y = i * height ; CCSprite * pCell = CCSprite::create(pImageName,CCRectMake(x,y,width,height)) ; pCell->setAnchorPoint(ccp(0,0)) ; const char* pName = CCString::createWithFormat(pSaveImageFromar,k,i,j)->getCString() ; CCRenderTexture* rrt = CCRenderTexture::create(width,height); rrt->clear(0,0); rrt->begin(); pCell ->visit(); rrt->end(); CCImage *pImage = rrt->newCCImage(true); std::string fullpath = CCFileUtils::sharedFileUtils()->getWritablePath() + pName; pImage->saveToFile(fullpath.c_str(),false); } } } }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。