本文整理汇总了C++中CCTexture2D::initWithImage方法的典型用法代码示例。如果您正苦于以下问题:C++ CCTexture2D::initWithImage方法的具体用法?C++ CCTexture2D::initWithImage怎么用?C++ CCTexture2D::initWithImage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCTexture2D
的用法示例。
在下文中一共展示了CCTexture2D::initWithImage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: init
bool
MCFaceBox::init(const char *aFaceFilepath, const char *aBoxFilepath)
{
do {
CCImage *aFaceImage = new CCImage;
CC_BREAK_IF(! aFaceImage);
CCImage *aBoxImage = new CCImage;
CC_BREAK_IF(! aBoxImage);
CCTexture2D *aFaceTexture = new CCTexture2D;
CC_BREAK_IF(! aFaceTexture);
CCTexture2D *aBoxTexture = new CCTexture2D;
CC_BREAK_IF(! aBoxTexture);
CC_BREAK_IF(! aFaceImage->initWithImageFile(aFaceFilepath));
CC_BREAK_IF(! aBoxImage->initWithImageFile(aBoxFilepath));
CC_BREAK_IF(! aFaceTexture->initWithImage(aFaceImage));
CC_BREAK_IF(! aBoxTexture->initWithImage(aBoxImage));
return init(aFaceTexture, aBoxTexture);
} while (0);
return false;
}
示例2: CreateBrick_Circle
ToyBrick* ToyLayer::CreateBrick_Circle()
{
int num = CommonHelper::GetRandomNum(1, 30);
//image && texture
char path[255];
sprintf(path, "Images/ToyBrick/Circle/%d.png", num);
CCImage *img = new CCImage();
img->autorelease();
if (!img->initWithImageFile(path, cocos2d::CCImage::kFmtPng))
{
return NULL;
}
CCTexture2D *texture = new CCTexture2D();
texture->autorelease();
if (!texture->initWithImage(img))
{
return NULL;
}
//
ToyBrick *brick = ToyBrick::create();
CCSize size = texture->getContentSize();
brick->Init(texture, CCRectMake(0, 0, size.width, size.height));
brick->SetAsCircle(64);
return brick;
}
示例3: handler_method_create_sprite
int Bitmap::handler_method_create_sprite(int bitmap_instance ,void* image)
{
Bitmap* bitmap = (Bitmap*)bitmap_instance;
CCSprite* sp = NULL;
CCImage* ccimage = (CCImage*)image;
if (image)
{
CCTexture2D* texture = new CCTexture2D;
texture->autorelease();
texture->initWithImage(ccimage);
sp = CCSprite::createWithTexture(texture);
CCAssert(sp,"fuck! image file error!");
bitmap->p->m_width = sp->getContentSize().width;
bitmap->p->m_height = sp->getContentSize().height;
}
else
{
sp = CCSprite::create();
sp->setContentSize(CCSizeMake(bitmap->p->m_width,bitmap->p->m_height));
}
//sp->getTexture()->setAliasTexParameters();
sp->retain();
bitmap->p->m_emuBitmap = sp;
delete ccimage;
return 0;
}
示例4: setRecHead
void ChatWidget::setRecHead(std::string *head)
{
float bw = 70;
float bh = 70;
if(head == 0 || head->size() == 0)
return;
if(m_toLabel)
m_toLabel->setVisible(false);
if(m_toHead && m_toHead->getParent()){
m_toHead->removeFromParentAndCleanup(true);
m_toHead = 0;
}
CCImage *img = new CCImage;
img->initWithImageData((void*)head->c_str(),head->size(),
CCImage::kFmtUnKnown);
CCTexture2D *texture = new CCTexture2D;
texture->initWithImage(img);
delete img;
m_toHead = CCSprite::create();
m_toHead->initWithTexture(texture);
CCSize headSize = m_toHead->getContentSize();
m_toHead->setScaleX(60 / headSize.width);
m_toHead->setScaleY(60 / headSize.height);
m_toButton->CCNode::addChild(m_toHead);
m_toHead->setAnchorPoint(ccp(0.5,0.5));
m_toHead->setPosition(ccp(bw/2,bh/2));
}
示例5: CCImage
AnimatedCell::AnimatedCell(int cellX, int cellY, int spacing, const char* pngFileName) {
this->setSpace(spacing);
this->setPngFileName(pngFileName);
animation_ = CCAnimation::create();
CCImage* image = new CCImage();
image->initWithImageFile(pngFileName);
CCTexture2D* texture = new CCTexture2D();
texture->initWithImage(image);
oneWidth_ = texture->getPixelsWide() / spacing;
oneHeight_ = texture->getPixelsHigh();
for (int i=0; i<spacing; i++) {
animation_->addSpriteFrameWithTexture(texture,
CCRectMake(i*oneWidth_, 0, oneWidth_, oneHeight_));
}
CCSpriteFrame* frm = ((CCAnimationFrame*)(animation_->getFrames()->objectAtIndex(0)))->getSpriteFrame();
this->initWithSpriteFrame(frm);
animation_->setDelayPerUnit(0.5f);
animate_ = CCRepeatForever::create(CCAnimate::create(animation_));
setCell(cellX, cellY);
}
示例6: CCImage
JNIEXPORT void JNICALL Java_game_mobile_infinity_FacebookManager_jniCallbackPicture(JNIEnv* env, jobject thiz, jstring jid , jbyteArray jimage)
{
const char *id = env->GetStringUTFChars( jid, 0);
CCString* cfbID = CCString::createWithFormat("%s",id);
int len = env->GetArrayLength(jimage);
char* byteData = (char*)malloc(len);
env->GetByteArrayRegion(jimage,0,len,(jbyte*)byteData);
CCImage* imf = new CCImage();
imf->initWithImageData(byteData,len);
imf->autorelease();
CCTexture2D* pTexture = new CCTexture2D();
pTexture->initWithImage(imf);
pTexture->autorelease();
CCSprite *sprit = CCSprite::createWithTexture(pTexture);
Facebook_Manager::sharedInstance()->Callback_Picture(cfbID, sprit);
env->ReleaseStringUTFChars( jid, id);
}
示例7: CreateArm
ToyBrick* DancingBoneLayer::CreateArm()
{
//image && texture
char path[255];
sprintf(path, "Images/DancingBone/arm.png");
CCImage *img = new CCImage();
img->autorelease();
if (!img->initWithImageFile(path, CCImage::kFmtPng))
{
return NULL;
}
CCTexture2D *texture = new CCTexture2D();
texture->autorelease();
if (!texture->initWithImage(img))
{
return NULL;
}
//
ToyBrick *brick = ToyBrick::create();
CCSize size = texture->getContentSize();
brick->Init(texture, CCRectMake(0, 0, size.width, size.height));
//vector (24, 102)
CCPointArray *vector = CCPointArray::create(4);
vector->addControlPoint(ccp(-12, -50));
vector->addControlPoint(ccp(12, -50));
vector->addControlPoint(ccp(12, 50));
vector->addControlPoint(ccp(-12, 50));
brick->SetAsPolygon(vector);
return brick;
}
示例8: getGrayTexture
CCTexture2D* Util::getGrayTexture(const char* filename){
typedef enum {
RED = 0,
GREEN = 1,
BLUE = 2,
ALPHA = 3
} PIXELS;
CCImage *image = new CCImage();
image->initWithImageFile(filename);
unsigned char* pixels = image->getData();
int len = image->getDataLen();
uint32_t *p = (uint32_t *)pixels;
for(int i=0;i<len;i++){
uint8_t *rgbaPixel = (uint8_t *) &p[i];
//uint32_t gray = 0.3 * rgbaPixel[RED] + 0.59 * rgbaPixel[GREEN] + 0.11 * rgbaPixel[BLUE];
uint32_t gray = 1.2*rgbaPixel[RED] + 1.0*rgbaPixel[GREEN] + 0.0*rgbaPixel[BLUE];
// set the pixels to gray
rgbaPixel[RED] = gray;
rgbaPixel[GREEN] = gray;
rgbaPixel[BLUE] = gray;
}
CCTexture2D* texture = new CCTexture2D();
texture->autorelease();
texture->initWithImage(image);
image->release();
return texture;
}
示例9: finish
void AskAsFriendDialog::finish()
{
LangDef *lang = ResourceMgr::getInstance()->getLangDef();
BasButton *okButton = new BasButton;
okButton->setButtonInfo(lang->getStringById(StringEnum::Ok).data(),"fonts/uifont24.fnt","default","buttonbg",
CCSizeMake(0,0));
okButton->setClickCB(m_okListener,m_okFunc);
this->addChild(okButton);
okButton->setBottomMargin(m_edgeSize);
okButton->setBottom("parent",uilib::Bottom);
okButton->setHorizontal("parent",0.75);
BasButton *rejectButton = new BasButton;
rejectButton->setButtonInfo(lang->getStringById(StringEnum::Reject).data(),"fonts/uifont24.fnt","default","buttonbg",
CCSizeMake(0,0));
rejectButton->setClickCB(m_rejectListener,m_rejectFunc);
this->addChild(rejectButton);
rejectButton->setBottomMargin(m_edgeSize);
rejectButton->setBottom("parent",uilib::Bottom);
rejectButton->setHorizontal("parent",0.25);
BasWidget *headWidget;
if(!m_askHead.empty()){
CCImage *img = new CCImage;
img->initWithImageData((void*)m_askHead.c_str(),m_askHead.size(),
CCImage::kFmtUnKnown);
CCTexture2D *texture = new CCTexture2D;
texture->initWithImage(img);
delete img;
CCSprite *sprite = CCSprite::create();
sprite->initWithTexture(texture);
headWidget = new BasNodeDelegateWidget(sprite);
this->addChild(headWidget);
headWidget->setHorizontal("parent",0.5);
headWidget->setVertical("parent",0.3);
}else{
CCSprite *sprite = CCSprite::createWithSpriteFrameName("headdefault.png");
headWidget = new BasNodeDelegateWidget(sprite);
this->addChild(headWidget);
headWidget->setHorizontal("parent",0.5);
headWidget->setVertical("parent",0.3);
}
m_askWord.insert(0," ");
TextScrollArea *area = new TextScrollArea;
area->setTheme("","");
area->setTextInfo(m_askWord,getSystemFont(),40,ccWHITE);
this->addChild(area);
area->setLeft("parent",uilib::Left);
area->setRight("parent",uilib::Right);
area->setLeftMargin(10);
area->setRightMargin(10);
area->setTop(headWidget->getName(),uilib::Bottom);
area->setBottom(rejectButton->getName(),uilib::Top);
}
示例10: onEnter
void EaseSpriteDemo::onEnter()
{
CCLayer::onEnter();
// Example:
// You can create a sprite using a Texture2D
CCTexture2D* tex = new CCTexture2D();
UIImage* pImage = new UIImage();
if(pImage->initWithContentsOfFile(CCFileUtils::fullPathFromRelativePath(s_pPathGrossini)))
{
tex->initWithImage(pImage);
m_grossini = CCSprite::spriteWithTexture(tex);
m_grossini->retain();
}
tex->release();
delete pImage;
// Example:
// Or you can create an sprite using a filename. PNG and BMP files are supported. Probably TIFF too
m_tamara = CCSprite::spriteWithFile(s_pPathSister1); m_tamara->retain();
m_kathia = CCSprite::spriteWithFile(s_pPathSister2); m_kathia->retain();
addChild( m_grossini, 3);
addChild( m_kathia, 2);
addChild( m_tamara, 1);
CGSize s = CCDirector::sharedDirector()->getWinSize();
m_grossini->setPosition( CGPointMake(60, 50) );
m_kathia->setPosition( CGPointMake(60, 150) );
m_tamara->setPosition( CGPointMake(60, 250) );
CCLabelTTF* label = CCLabelTTF::labelWithString(title().c_str(), "Arial", 32);
addChild(label);
label->setPosition( CGPointMake(s.width/2, s.height-50) );
CCMenuItemImage *item1 = CCMenuItemImage::itemFromNormalImage(s_pPathB1, s_pPathB2, this, menu_selector(EaseSpriteDemo::backCallback) );
CCMenuItemImage *item2 = CCMenuItemImage::itemFromNormalImage(s_pPathR1, s_pPathR2, this, menu_selector(EaseSpriteDemo::restartCallback) );
CCMenuItemImage *item3 = CCMenuItemImage::itemFromNormalImage(s_pPathF1, s_pPathF2, this, menu_selector(EaseSpriteDemo::nextCallback) );
CCMenu *menu = CCMenu::menuWithItems(item1, item2, item3, NULL);
menu->setPosition( CGPointZero );
item1->setPosition( CGPointMake( s.width/2 - 100,30) );
item2->setPosition( CGPointMake( s.width/2, 30) );
item3->setPosition( CGPointMake( s.width/2 + 100,30) );
addChild(menu, 1);
}
示例11: generateSnapshot
CCSprite* XieziLayer::generateSnapshot(){
CCSize mainSize=S_RM->getSizeWithName("xiezi_webview_size");
CCPoint mainPoint=S_RM->getPositionWithName("xiezi_main");
CCSprite* snapshot=(CCSprite*)this->getChildByTag(kTagSnapshot);
const char* data=m_webView->callWebWithJs("getCanvasBase64Data()");
int length=(int)strlen(data);
if(length>0){
string pngData=StringUtils::base64Decode(data, (int)strlen(data));
CCImage* img=new CCImage();
img->autorelease();
img->initWithImageData(const_cast<char*>(pngData.c_str()), (int)pngData.length());
CCTexture2D *texture = new CCTexture2D();
texture->initWithImage(img);
texture->autorelease();
if (snapshot) {
snapshot->setTexture(texture);
}else{
snapshot= CCSprite::createWithTexture(texture);
snapshot->setPosition(mainPoint);
snapshot->setTag(kTagSnapshot);
if (mainSize.width!=snapshot->getContentSize().width) {
snapshot->setScale(mainSize.width/snapshot->getContentSize().width);
}
this->addChild(snapshot);
}
}else{
if (!snapshot) {
snapshot=CCSprite::createWithSpriteFrameName("tianzige.png");
snapshot->setPosition(mainPoint);
CCLabelTTF* label=CCLabelTTF::create(m_hanzi->getzi().c_str(), "KaiTi.ttf", 400.0);
label->setColor(ccc3(100,53,14));
label->setPosition(ccp(mainSize.width/2, mainSize.height/2));
snapshot->addChild(label);
snapshot->setTag(kTagSnapshot);
this->addChild(snapshot);
}
}
return snapshot;
}
示例12: imageLoadSuccessCallBack
void CMainCityUI::imageLoadSuccessCallBack(string sTag, vector<char>* pBuffer)
{
CCImage* img = new CCImage;
img->initWithImageData((unsigned char*)pBuffer->data(), pBuffer->size());
CCTexture2D* texture = new CCTexture2D();
texture->initWithImage(img);
CLayout* headPart = (CLayout*)m_ui->findWidgetById("head_part");
CCSprite* head = (CCSprite*)headPart->getChildByTag(15);
// head->removeFromParent();
//head->setTexture(texture);
string path = HttpLoadImage::getInstance()->getStoragePath("download/fbImg",sTag.c_str())+".jpg";
string buff(pBuffer->begin(), pBuffer->end());
CCLOG("path: %s", path.c_str());
FILE *fp = fopen(path.c_str(), "wb+");
fwrite(buff.c_str(), 1, pBuffer->size(), fp);
fclose(fp);
// CCSprite *headbg = (CCSprite*)(m_ui->findWidgetById("headbg"));
// CCClippingNode *clip = CCClippingNode::create();
// CCSprite *fbimg = CCSprite::createWithTexture(texture);
// clip->addChild(fbimg);
//
// clip->setPosition(headbg->getPosition());
// clip->setContentSize(CCSizeMake(110,110));
//
// static ccColor4F red ={1,0,1};
// float radius = 106;
// const int nCount = 200;
// const float angle = 2.0f* (float)M_PI/nCount;
// CCPoint circle[nCount];
// for(int i=0; i<nCount; i++)
// {
// float radian = i*angle;
// circle[i].x = radius * cosf(radian);
// circle[i].y = radius * sinf(radian);
// }
// CCDrawNode *stencil= CCDrawNode::create();
// stencil->drawPolygon(circle,nCount,red,0,red);
// clip->setStencil(stencil);
// m_ui->addChild(clip);
CCSprite *headBg = (CCSprite *)(headPart->findWidgetById("headbg"));
CCSprite *headSpr = MakeFaceBookHeadToCircle(CCSprite::createWithTexture(texture));
headSpr->setTag(15);
headSpr->setPosition(headBg->getPosition());
headPart->addChild(headSpr);
head->removeFromParent();
img->release();
}
示例13: init
bool MainMenuBtnLayer::init()
{
bool bRet = false;
do
{
// Super init first
CC_BREAK_IF(!CCLayer::init());
CCSize size = CCDirector::sharedDirector()->getWinSize();
CCImage menufile;
menufile.initWithImageFile("Buttons.png");
CCTexture2D *menuTexture = new CCTexture2D();
menuTexture->initWithImage(&menufile);
CCMenuItemSprite *startgameitem = CCMenuItemSprite::create(CCSprite::createWithTexture(menuTexture, CCRectMake(6, 2, 166, 28)),
CCSprite::createWithTexture(menuTexture, CCRectMake(6, 35, 166, 28)),
CCSprite::createWithTexture(menuTexture, CCRectMake(6, 70, 166, 28)),
this, menu_selector (MainMenuBtnLayer::menucallback));
startgameitem->setTag(MAINMENU_ID_START);
CCMenuItemSprite *settings = CCMenuItemSprite::create(CCSprite::createWithTexture(menuTexture, CCRectMake(188, 2, 166, 28)),
CCSprite::createWithTexture(menuTexture, CCRectMake(188, 35, 166, 28)),
CCSprite::createWithTexture(menuTexture, CCRectMake(188, 70, 166, 28)),
this, menu_selector (MainMenuBtnLayer::menucallback));
settings->setTag(MAINMENU_ID_SETTING);
CCMenuItemSprite *about = CCMenuItemSprite::create(CCSprite::createWithTexture(menuTexture, CCRectMake(370, 2, 166, 28)),
CCSprite::createWithTexture(menuTexture, CCRectMake(370, 35, 166, 28)),
CCSprite::createWithTexture(menuTexture, CCRectMake(370, 70, 166, 28)),
this, menu_selector (MainMenuBtnLayer::menucallback));
about->setTag(MAINMENU_ID_ABOUT);
CCMenuItemSprite *quit = CCMenuItemSprite::create(CCSprite::createWithTexture(menuTexture, CCRectMake(552, 2, 166, 28)),
CCSprite::createWithTexture(menuTexture, CCRectMake(552, 35, 166, 28)),
CCSprite::createWithTexture(menuTexture, CCRectMake(552, 70, 166, 28)),
this, menu_selector (MainMenuBtnLayer::menucallback));
quit->setTag(MAINMENU_ID_QUIT);
CCMenu *menu = CCMenu::create(startgameitem, settings, about, quit, NULL);
menu->alignItemsVerticallyWithPadding(10);
menu->setPosition(ccp(size.width * 0.5f, size.height * 0.5f));
this->addChild(menu);
bRet = true;
} while(0);
return bRet;
}
示例14: updateSquare
void HelloWorld::updateSquare(float tm){
for(int i = 0; i < 64; i++){
CCSprite *sprite = diamonds[i];
char str[20];
CCImage *image = new CCImage();
int color = getDiamond(str);
base[i] = color;
image->initWithImageFile(str, CCImage::kFmtJpg);
CCTexture2D* texture = new CCTexture2D();
texture->initWithImage(image);
sprite->setTexture(texture);
}
}
示例15: ccTouchEnded
void HelloWorld::ccTouchEnded(cocos2d::CCTouch *pTouches, cocos2d::CCEvent *pEvent){
if(m_score<0){
return;
}
CCPoint point = pTouches->getLocation();
char pos[100];
int y_ = (int)((point.y-diamondRect.origin.y)/dh);
int y = 7-y_;
int x = (int)((point.x-diamondRect.origin.x)/dw);
int result[64] = {0};
if(y>=8||x>=8){
return;
}
int count = handlerTouchInSquare(y*8+x, result);
if(count < 3)
return;
for(int i = 0; i < count; i++){
CCSprite *sprite = diamonds[result[i]];
CCRotateBy *rotateAct = new CCRotateBy();
rotateAct->initWithDuration(0.2f, 90.0f);
sprite->runAction(rotateAct);
char str[20];
CCImage *image = new CCImage();
int color = getDiamond(str);
base[result[i]] = color;
image->initWithImageFile(str, CCImage::kFmtJpg);
CCTexture2D* texture = new CCTexture2D();
texture->initWithImage(image);
sprite->setTexture(texture);
}
//delete rotateAct;
m_score += 5*count;
char str[20];
sprintf(str, "Score: %d", m_score);
pLabelScore->setString(str);
//fflush(file);
}