本文整理汇总了C++中CCTexture2D::autorelease方法的典型用法代码示例。如果您正苦于以下问题:C++ CCTexture2D::autorelease方法的具体用法?C++ CCTexture2D::autorelease怎么用?C++ CCTexture2D::autorelease使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCTexture2D
的用法示例。
在下文中一共展示了CCTexture2D::autorelease方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addPVRTCImage
CCTexture2D* CCTextureCache::addPVRTCImage(const char* path, int bpp, bool hasAlpha, int width)
{
CCAssert(path != NULL, "TextureCache: fileimage MUST not be nill");
CCAssert( bpp==2 || bpp==4, "TextureCache: bpp must be either 2 or 4");
CCTexture2D * texture;
std::string temp(path);
if ( (texture = m_pTextures->objectForKey(temp)) )
{
return texture;
}
// Split up directory and filename
std::string fullpath( CCFileUtils::fullPathFromRelativePath(path) );
CCData * data = CCData::dataWithContentsOfFile(fullpath);
texture = new CCTexture2D();
texture->initWithPVRTCData(data->bytes(), 0, bpp, hasAlpha, width);
if( texture )
{
m_pTextures->setObject(texture, temp);
texture->autorelease();
}
else
{
CCLOG("cocos2d: Couldn't add PVRTCImage:%s in CCTextureCache",path);
}
CC_SAFE_DELETE(data);
return texture;
}
示例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: key
CCTexture2D * CCTextureCache::addPVRTCImage(const char* fileimage)
{
CCAssert(fileimage != NULL, "TextureCache: fileimage MUST not be nill");
CCTexture2D * texture;
std::string key(fileimage);
if( (texture = m_pTextures->objectForKey(key)) )
{
return texture;
}
texture = new CCTexture2D();
texture = texture->initWithPVRTCFile(fileimage);
if( texture )
{
m_pTextures-> setObject( texture, key);
texture->autorelease();
}
else
{
CCLOG("cocos2d: Couldn't add PVRTCImage:%s in CCTextureCache",fileimage);
}
return texture;
}
示例4: 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);
}
示例5: 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;
}
示例6: 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;
}
示例7: 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;
}
示例8: 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;
}
示例9: CreateBrick_Rectangle
ToyBrick* ToyLayer::CreateBrick_Rectangle()
{
int num = CommonHelper::GetRandomNum(1, 20);
//image && texture
char path[255];
sprintf(path, "Images/ToyBrick/Rectangle/%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));
//vector
CCPointArray *vector = CCPointArray::create(4);
vector->addControlPoint(ccp(-52, -52));
vector->addControlPoint(ccp(52, -52));
vector->addControlPoint(ccp(52, 52));
vector->addControlPoint(ccp(-52, 52));
brick->SetAsPolygon(vector);
return brick;
}
示例10: addUIImage
/* @todo CGImageRef
-(CCTexture2D*) addCGImage: (CGImageRef) imageref forKey: (string & )key
{
CCAssert(imageref != nil, @"TextureCache: image MUST not be nill");
CCTexture2D * tex = nil;
// If key is nil, then create a new texture each time
if( key && (tex=[textures objectForKey: key] ) ) {
return tex;
}
// prevents overloading the autorelease pool
UIImage *image = [[UIImage alloc] initWithCGImage:imageref];
tex = [[CCTexture2D alloc] initWithImage: image];
[image release];
if(tex && key)
[textures setObject: tex forKey:key];
else
CCLOG(@"cocos2d: Couldn't add CGImage in CCTextureCache");
return [tex autorelease];
}*/
CCTexture2D* CCTextureCache::addUIImage(CCImage *image, const char *key)
{
CCAssert(image != NULL && key != NULL, "TextureCache: image MUST not be nill");
CCTexture2D * texture = NULL;
std::string forKey = key;
m_pDictLock->lock();
do
{
// If key is nil, then create a new texture each time
if(texture = m_pTextures->objectForKey(forKey))
{
break;
}
// prevents overloading the autorelease pool
texture = new CCTexture2D();
texture->initWithImage(image);
if(texture)
{
m_pTextures->setObject(texture, forKey);
texture->autorelease();
}
else
{
CCLOG("cocos2d: Couldn't add UIImage in CCTextureCache");
}
} while (0);
m_pDictLock->unlock();
return texture;
}
示例11: constructView
void SGCGMovieLayer::constructView()
{
SGNotificationCenter::sharedNotificationCenter()->addObserver(MSG_CGBATTLE_START, this, callfuncO_selector(SGCGMovieLayer::cgBattleListener));
s = CCDirector::sharedDirector()->getWinSize();
ResourceManager::sharedInstance()->bindTexture("bg/cgBg.plist", RES_TYPE_LAYER_UI, sg_cgMovieLayer);
CCSprite *cgBg = CCSprite::createWithSpriteFrameName("cgBg.png");
cgBg->setAnchorPoint(ccp(0.5, 1));
cgBg->ignoreAnchorPointForPosition(false);
cgBg->cocos2d::CCNode::setScaleX(s.width/cgBg->getContentSize().width);
cgBg->setPosition(ccp(s.width/2, s.height));
addChild(cgBg);
// SGButton *skipBt = SGButton::createFromLocal("box_btnbg.png", "跳 过", this, menu_selector(SGCGMovieLayer::cgSkipToBattle), CCPointZero, FONT_PANGWA,ccWHITE,32,false,true);
// skipBt->setPosition(ccp(s.width/2, skipBt->getContentSize().height*2));
// addBtn(skipBt);
CCLayerColor * blackBg = CCLayerColor::create(ccc4(0, 0, 0, 255), s.width, s.height);
blackBg->setTouchEnabled(false);
blackBg->ignoreAnchorPointForPosition(false);
blackBg->setAnchorPoint(ccp(0, 0));
blackBg->setPosition(ccp(0, 0));
this->addChild(blackBg, -100);
scrollRect = CCRectMake(0, s.height*0.2, s.width, s.height/4);
cgScrollView = SNSScrollView::create(scrollRect);
cgScrollView->setFrame(scrollRect);
cgScrollView->setPosition(scrollRect.origin);
cgScrollView->setHorizontal(false);
cgScrollView->setVertical(true);
cgScrollView->setTouchEnabled(false);
this->addChild(cgScrollView);
// CCSprite *scrollBg = CCSprite::createWithSpriteFrameName("barrack_kuang.png");
// scrollBg->cocos2d::CCNode::setScale(s.width/scrollBg->getContentSize().width, s.height/4/scrollBg->getContentSize().height);
// scrollBg->setPosition(ccpAdd(scrollRect.origin, ccp(s.width/2, s.height/8)));
// addChild(scrollBg);
char *spritData = new char[(int)s.width * (int)s.height *4];
memset(spritData,0,(int)s.width * (int)s.height *4);
int spriteDataSize = (int)s.width * (int)s.height*4;
for (int j=0; j<spriteDataSize; j+=4) {
spritData[j] = 0;
spritData[j+1] = 0;
spritData[j+2] = 0;
spritData[j+3] = 255;
}
CCTexture2D *pTexture = new CCTexture2D();
pTexture->initWithData(spritData, kCCTexture2DPixelFormat_Default, (int)s.width, (int)s.height, s);
finaleSprite = CCSprite::createWithTexture(pTexture);
finaleSprite->setPosition(CCPointZero);
finaleSprite->setAnchorPoint(CCPointZero);
this->addChild(finaleSprite,10,10);
finaleSprite->setVisible(false);
finaleSprite->setOpacity(0);
delete [] spritData;
pTexture->autorelease();
this->setTouchEnabled(true);
const char *str[7] = { str_CGMovieLayer_str1,
str_CGMovieLayer_str2,
str_CGMovieLayer_str3,
str_CGMovieLayer_str4,
str_CGMovieLayer_str5,
str_CGMovieLayer_str6,
str_CGMovieLayer_str7};
SGCCLabelTTF *cgMsg = NULL;
posY = -20;
for (int i=0; i<7; i++) {
cgMsg = SGCCLabelTTF::create(str[i], FONT_BOXINFO, 34);
cgMsg->cocos2d::CCNode::setPosition(s.width/2, posY);
cgScrollView->m_body->addChild(cgMsg);
posY -= 50;
}
moveCgMsgDis = CGMSGMOVEDIS;
unschedule(schedule_selector(SGCGMovieLayer::moveCgMsgUp));
if (SGPlayerInfo::sharePlayerInfo()->getCDKeyNeed()==1) {
SGNotificationCenter::sharedNotificationCenter()->addObserver(MSG_CDK, this, callfuncO_selector(SGCGMovieLayer::cdkListener));
ResourceManager::sharedInstance()->bindTexture("sgloginingbox/sgloginingbox.plist", RES_TYPE_LAYER_UI, sg_cgMovieLayer);
// ResourceManager::sharedInstance()->bindTexture("sgserverlistlayer/sgserverlistlayer.plist",RES_TYPE_LAYER_UI ,sg_registerLayer);
box = CCSprite::createWithSpriteFrameName("register_diban.png");
box->setPosition(SGLayout::getPoint(kMiddleCenter));
this->addChild(box);
m_cdk = CCEditBox::create(CCSizeMake(500, 60), CCScale9Sprite::createWithSpriteFrameName("public_kuang_input.png"));
m_cdk->setPlaceHolder(str_CGMovieLayer_str8);
m_cdk->setPlaceholderFontColor(ccc3(0x82,0x3e,0x02));
m_cdk->setMaxLength(10);
m_cdk->setReturnType(kKeyboardReturnTypeDone);
//.........这里部分代码省略.........
示例12: setLocalSrc
void MRemoteSprite::setLocalSrc(std::string srcLocalPath)
{
srcLocalPath = MFileDownloader::getLocalFilePath(srcLocalPath);
if (_sprite != nullptr)
{
_sprite->removeFromParent();
_sprite = nullptr;
}
CCImage *image = nullptr;
if (isSpecialSrc(srcLocalPath))
{
image = get_special_ccimage(srcLocalPath, getOpacitySrc(srcLocalPath));
}
else if (isSpecialSrcSmall(srcLocalPath))
{
image = get_special_ccimage(srcLocalPath, getOpacitySrcSmall(srcLocalPath));
}
else
{
image = get_ccimage(srcLocalPath);
}
if (image == nullptr)
{
M_DEBUG( "!!! get image failed, file >> " << srcLocalPath );
this->dispatchEvent(EVENT_CARD_DOWNLOAD_OK);
return ;
}
CCTexture2D *texture = nullptr;
if (isGray())
{
texture = mlib::create_gray_texture(image);
}
else
{
texture = new CCTexture2D();
texture->autorelease();
if( texture &&
texture->initWithImage(image) )
{
}
}
if (texture != nullptr)
{
if (sizeShow().equals(CCSizeZero))
{
_sprite = MSprite::createWithTexture(texture);
}
else
{
CCSize cSize = texture->getContentSize();
_sprite = MSprite::createWithTexture(texture, CCRectMake((cSize.width - sizeShow().width) / 2, (cSize.height - sizeShow().height) / 2, sizeShow().width, sizeShow().height));
}
}
if (_sprite != nullptr)
{
if (alignment() == RemoteSpritAlignmentBottom)
{
_sprite->setAnchorPoint(ccp(0.5, 0));
_sprite->setPosition(ccp(getContentSize().width/2, 0));
}
else // default alignment: center
{
_sprite->setAnchorPoint(ccp(0.5, 0.5));
_sprite->setPosition(ccp(getContentSize().width/2, getContentSize().height/2));
}
_sprite->setColor(_color);
_sprite->setOpacity(_opacity);
this->addChild(_sprite);
_srcPath = srcLocalPath;
}
_isGrayChange = false;
this->dispatchEvent(EVENT_CARD_DOWNLOAD_OK);
}
示例13: init
KDbool CCSpriteBatchNode::init ( KDvoid )
{
CCTexture2D* pTexture = new CCTexture2D ( );
pTexture->autorelease ( );
return this->initWithTexture ( pTexture, 0 );
}
示例14: init
bool CCSpriteBatchNode::init()
{
CCTexture2D * texture = new CCTexture2D();
texture->autorelease();
return this->initWithTexture(texture, 0);
}
示例15: draw
void HelloWorld::draw()
{
//这里需要绘制格子了。。
CCPoint pt1;
CCPoint pt2;
for (int i = 0 ; i < 16 ; i++)
{
for (int j =0 ; j < 8; j++) {
int x = m_CurrentMapStartPos.y +j;
int y = m_CurrentMapStartPos.x +i;
if (map[x][y] != 1) {
ccDrawColor4B(255, 0, 0, 125);
}
else
{
if(map[x][y] == 2){
ccDrawColor4B(0, 255, 255, 125);
}
else
{
ccDrawColor4B(0, 255, 0, 125);
}
}
pt1.x = i*64 ;
pt1.y = j*64+m_border;
pt2.x = (i+1)*64;
pt2.y = (j+1)*64+m_border;
ccDrawRect(pt1, pt2);
{
char num[20];
CCTexture2D* tex = new CCTexture2D();
sprintf(num, "%d,%d",(int)m_CurrentMapStartPos.x + i,(int)m_CurrentMapStartPos.y +j);
tex->initWithString(num, "Arial", 15);
CCRect rect = CCRectMake(pt1.x,pt1.y,30,30);
tex->drawInRect(rect);
tex->autorelease();
}
}
}
char PlayerPos[20];
CCTexture2D* tex = new CCTexture2D();
sprintf(PlayerPos, "playerPos:%d,%d",(int)m_CurrentPos.x,(int)m_CurrentPos.y);
tex->initWithString(PlayerPos, "Arial", 15);
CCRect rect = CCRectMake(10,700,100,30);
tex->drawInRect(rect);
tex->autorelease();
char CurrentmapstartPos[20];
CCTexture2D* tex1 = new CCTexture2D();
sprintf(CurrentmapstartPos, "CurrentmapstartPos:%d,%d",(int)m_CurrentMapStartPos.x,(int)m_CurrentMapStartPos.y);
tex1->initWithString(CurrentmapstartPos, "Arial", 15);
CCRect rect1 = CCRectMake(10,730,100,30);
tex1->drawInRect(rect1);
tex1->autorelease();
CCLayer::draw();
}