当前位置: 首页>>代码示例>>C++>>正文


C++ CCTexture2D类代码示例

本文整理汇总了C++中CCTexture2D的典型用法代码示例。如果您正苦于以下问题:C++ CCTexture2D类的具体用法?C++ CCTexture2D怎么用?C++ CCTexture2D使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了CCTexture2D类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: CCAssert

bool CCSprite::initWithFile(const char *pszFilename)
{
    CCAssert(pszFilename != NULL, "Invalid filename for sprite");

    CCTexture2D *pTexture = CCTextureCache::sharedTextureCache()->addImage(pszFilename);
    if (pTexture)
    {
        CCRect rect = CCRectZero;
        rect.size = pTexture->getContentSize();
        setSpriteImageName(pszFilename);
        return initWithTexture(pTexture, rect);
    }

    // don't release here.
    // when load texture failed, it's better to get a "transparent" sprite then a crashed program
    // this->release(); 
    return false;
}
开发者ID:vedi,项目名称:cocos2d-x,代码行数:18,代码来源:CCSprite.cpp

示例2: addChild

// on "init" you need to initialize your instance
bool MainMenuScene::init()
{
    CCSprite *fondo = CCSprite::create("fondo.png");
    fondo->setPosition(VisibleRect::center());
    addChild(fondo);
    
    CCSprite *leftGrass = CCSprite::create("grass_left.png");
    leftGrass->setAnchorPoint(ccp(0,0));
    leftGrass->setPosition(VisibleRect::leftBottom());
    addChild(leftGrass);
    CCSprite *rightGrass = CCSprite::create("grass_right.png");
    rightGrass->setAnchorPoint(ccp(1,0));
    rightGrass->setPosition(VisibleRect::rightBottom());
    addChild(rightGrass);
    
    CCSprite *spriteLogo = CCSprite::create("logo_opciones.png");
    spriteLogo->setPosition(ccp(VisibleRect::center().x, (VisibleRect::top().y - (spriteLogo->getContentSize().height / 2) - 20)));
    addChild(spriteLogo);
    
    int mySize = VisibleRect::center().y / 3;
    
    CCTexture2D *texture = CCTextureCache::sharedTextureCache()->addImage("botoia_normal.png");
    
    CCPoint anchorPoint = ccp(0.5f, 0.5f);
    
    CCLabelTTF *pLabel1 = CCLabelTTF::create("Jokatu", "fonts/PT_Sans-Web-Bold.ttf", 30.0);
    CCLabelTTF *pLabel2 = CCLabelTTF::create("Sailkapena", "fonts/PT_Sans-Web-Bold.ttf", 30.0);
    CCLabelTTF *pLabel3 = CCLabelTTF::create("Honi Buruz", "fonts/PT_Sans-Web-Bold.ttf", 30.0);
    
    // Button JOKATU
    SpriteButton *pButton1 = SpriteButton::create(texture ,this, callfuncO_selector(MainMenuScene::menuSelector), 1.0f);
    pButton1->setTag(1);
    pButton1->setAnchorPoint(anchorPoint);
    pButton1->setPosition(ccp(VisibleRect::center().x, (mySize * 3) - texture->getContentSize().height /2));
    pLabel1->setPosition(ccp(VisibleRect::center().x, (mySize * 3) - texture->getContentSize().height /2));
    
    // Button SAILKAPENA
    SpriteButton *pButton2 = SpriteButton::create(texture ,this, callfuncO_selector(MainMenuScene::menuSelector), 1.0f);
    pButton2->setTag(2);
    pButton2->setAnchorPoint(anchorPoint);
    pButton2->setPosition(ccp(VisibleRect::center().x, (mySize * 2) - texture->getContentSize().height /2));
    pLabel2->setPosition(ccp(VisibleRect::center().x, (mySize * 2) - texture->getContentSize().height /2));
    
    // Button HONI BURUZ
    SpriteButton *pButton3 = SpriteButton::create(texture ,this, callfuncO_selector(MainMenuScene::menuSelector), 1.0f);
    pButton3->setTag(3);
    pButton3->setAnchorPoint(anchorPoint);
    pButton3->setPosition(ccp(VisibleRect::center().x, mySize - texture->getContentSize().height /2));
    pLabel3->setPosition(ccp(VisibleRect::center().x, mySize - texture->getContentSize().height /2));
    
    addChild(pButton1);
    addChild(pLabel1);
    addChild(pButton2);
    addChild(pLabel2);
    addChild(pButton3);
    addChild(pLabel3);
    
	return true;
}
开发者ID:aandroiderr,项目名称:Auskalo,代码行数:60,代码来源:MainMenuScene.cpp

示例3: spriteWithFile

Player* Player::spriteWithFile(const char *pszFileName, int columns, int rows)
{
//	CCSpriteFrame *frame = cacher->spriteFrameByName( pszFileName);
	CCTexture2D *texture = CCTextureCache::sharedTextureCache()->addImage(pszFileName);
	CCArray* aFrames = CCArray::createWithCapacity(columns * rows);


	float textureWidth =  texture->getPixelsWide();
	float textureHeight = texture->getPixelsHigh();
	float frameWidth = textureWidth / columns;
	float frameHeight = textureHeight / rows;

	for (int c = 0; c < columns; c++)
	{
		for (int r = 0; r < rows; r++)
		{
			CCSpriteFrame *frame0 = CCSpriteFrame::createWithTexture(texture, CCRectMake((c*frameWidth), (r*frameHeight), 100, 65));
			aFrames->addObject(frame0);
		}

	}

	CCAnimation *animation = CCAnimation::createWithSpriteFrames(aFrames, 0.2f);
	CCAnimate *animate = CCAnimate::create(animation);
	CCActionInterval* seq = (CCActionInterval*)(CCSequence::create( animate,   animate->copy()->autorelease(),   CCFlipX::create(false),   NULL) );

	Player *pobSprite = new Player();
	if (pobSprite && pobSprite->initWithSpriteFrame((CCSpriteFrame*) aFrames->objectAtIndex(0)))
	{
		pobSprite->scheduleUpdate();
		pobSprite->autorelease();
		pobSprite->setForwardMarch(false);
		pobSprite->setMightAsWellJump(false);
		pobSprite->setBackwardMarch(false);
		pobSprite->runAction(CCRepeatForever::create( seq ) );
	//	pobSprite->setAnimFrames( aFrames);
	//	pobSprite->setCurrentFrame(0);

		return pobSprite;
	}
	CC_SAFE_DELETE(pobSprite);
	return NULL;
}
开发者ID:dps999,项目名称:mario,代码行数:43,代码来源:Player.cpp

示例4: handlerTouchInSquare

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);
}
开发者ID:huneng,项目名称:EliminateDiamond,代码行数:42,代码来源:HelloWorldScene.cpp

示例5: CCTexture2D

// Helper
void CCLabelTTF::updateTexture()
{
    CCTexture2D *tex;
    if (m_tDimensions.width == 0 || m_tDimensions.height == 0)
    {
        tex = new CCTexture2D();
        tex->initWithString(m_string.c_str(), m_pFontName->c_str(), m_fFontSize * CC_CONTENT_SCALE_FACTOR()) ;
    }
    else
    {
        tex = new CCTexture2D();
        tex->initWithString(m_string.c_str(),
                            CC_SIZE_POINTS_TO_PIXELS(m_tDimensions),
                            m_hAlignment,
                            m_vAlignment,
                            m_pFontName->c_str(),
                            m_fFontSize * CC_CONTENT_SCALE_FACTOR());
    }

    // iPad ?
    //if( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ) {
    if (CCApplication::sharedApplication().isIpad())
    {
        if (CC_CONTENT_SCALE_FACTOR() == 2)
        {
            tex->setResolutionType(kCCResolutioniPadRetinaDisplay);
        }
        else
        {
            tex->setResolutionType(kCCResolutioniPad);
        }
    }
    // iPhone ?
    else
    {
        if (CC_CONTENT_SCALE_FACTOR() == 2)
        {
            tex->setResolutionType(kCCResolutioniPhoneRetinaDisplay);
        }
        else
        {
            tex->setResolutionType(kCCResolutioniPhone);
        }
    }

    this->setTexture(tex);
    tex->release();

    CCRect rect = CCRectZero;
    rect.size = m_pobTexture->getContentSize();
    this->setTextureRect(rect);
}
开发者ID:rohankuruvilla,项目名称:cocos2dx-watermelon-ios,代码行数:53,代码来源:CCLabelTTF.cpp

示例6: HS_FIND_UI_PANEL_SPRITE

void HSEmailSystemLayer::Load()
{
    CCSprite* pBackground = HSCCSprite::create("Image/BEIJING.png");
	pBackground->setPosition(HSBase::GetTemplateScreenCentre());
	this->addChild(pBackground);
	HSTool::SetNodeFilldScreen(pBackground);
    
	HSReadUI::ShareReadUI()->ReadUI("Image/EmailSystem.data","Image/",this);

	CCSprite* pMoneyFrame = HS_FIND_UI_PANEL_SPRITE("UI_Jinbidiandikuang","Jinbidiandikuang");
	CCTexture2D* pMoneyTexture = CCTextureCache::sharedTextureCache()->addImage("Image/moneyNumber.png");
	m_pMoney =  CCLabelAtlas::create("0","Image/moneyNumber.png",pMoneyTexture->getPixelsWide() / 11,pMoneyTexture->getPixelsHigh(),'0');
	m_pMoney->setAnchorPoint(HS_ANCHOR_CENTER);
	m_pMoney->setPosition(HS_SizeHalf_Point(pMoneyFrame->getContentSize()));
	pMoneyFrame->addChild(m_pMoney);


	CCSprite* pEmailSystemFrame = HS_FIND_UI_PANEL_SPRITE("UI_FriendFrame","gerenxinxilanfanwei");
	m_pEmailListView = HSEmailListVeiw::create(pEmailSystemFrame->getContentSize(),CCSizeMake(505,100),HS_GAME_CACHE()->m_EmailResponse.emaillist_size());
	CCPoint pos = CCPointZero;
	pos.x = -pEmailSystemFrame->getContentSize().width / 2.f - 15.f;

	pos.y = pEmailSystemFrame->getPosition().y - pEmailSystemFrame->getContentSize().height / 2.f - 20.f;
	m_pEmailListView->setPosition(pos);
	pEmailSystemFrame->getParent()->addChild(m_pEmailListView,1000);
	m_pEmailListView->reloadData();

	HS_SET_MENU_TARGET("UI_fh_01",this,HSEmailSystemLayer::Call_Back);

	HS_SET_MENU_TARGET("UI_Goumaijinbianniu_01",this,HSEmailSystemLayer::Call_Shop);
    
    if (HS_GAME_CACHE()->m_EmailResponse.emaillist_size() == 0)
    {
        CCMenu* pMenu = HS_FIND_UI_MENU("UI_quanbulingqu");
        pMenu->setVisible(false);
    }else{
        HS_SET_MENU_TARGET("UI_quanbulingqu",this,HSEmailSystemLayer::Call_AllRevc);
    }
    

	this->schedule(schedule_selector(HSEmailSystemLayer::Updata));
}
开发者ID:wanggan768q,项目名称:GameWork,代码行数:42,代码来源:HSEmailSystemScene.cpp

示例7: getTexture

CCTexture2D* getTexture(std::string theImageFullPath, CCRect& theTextureRect){
	// try to load from sprite sheet
	std::string anImageFileName;
	int aLastSlashIndex = MAX((int)theImageFullPath.find_last_of('/'), (int)theImageFullPath.find_last_of('\\'));
	if (aLastSlashIndex != std::string::npos) {
		anImageFileName = theImageFullPath.substr(aLastSlashIndex + 1);
	} else {
		anImageFileName = theImageFullPath;
	}
	CCSpriteFrame *aSpriteFrame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(anImageFileName.c_str());
	if (aSpriteFrame) {
		theTextureRect = aSpriteFrame->getRect();
		return aSpriteFrame->getTexture();
	}
	
	CCTexture2D* aTexture = CCTextureCache::sharedTextureCache()->addImage(theImageFullPath.c_str());
	theTextureRect.origin = CCPointZero;
	theTextureRect.size = aTexture->getContentSize();
	return aTexture;
}
开发者ID:xiangry,项目名称:cocos2dx-classical,代码行数:20,代码来源:CCSuperAnim.cpp

示例8: setPositionByProperty

bool ItemFireString::init(CCDictionary * dict)
{
	Item::init();
	_type = IT_FIRESTRING;
	setPositionByProperty(dict);

	CCTexture2D * bossBullet = CCTextureCache::sharedTextureCache()->addImage("bossBullet.png");
	setTexture(bossBullet);
	setTextureRect(CCRectMake(0, 0, bossBullet->getContentSize().width, bossBullet->getContentSize().height));
	setScale(.6f);

	setAnchorPoint(ccp(0, 0.5f));

	int begAngle  = dict->valueForKey("begAngle")->intValue();
	setRotation(begAngle);
	int time = dict->valueForKey("time")->intValue();
	runAction(CCRepeatForever::create(CCRotateBy::create(time, 360)));

	return true;
}
开发者ID:hcy12321,项目名称:Cocos2dx2TestsMario,代码行数:20,代码来源:ItemFireString.cpp

示例9: generateBackground

	void TilemapRender::generateBackground()
	{
		ostringstream texturePath;
		texturePath<<"resources.pak/terrain/";
		texturePath<<m_SetID<<"-14.png";
		
		CCRenderTexture* rt = CCRenderTexture::create(64,64);
		rt->begin();
		CCSprite* tile1 = CCSprite::create(texturePath.str().c_str());
		tile1->setAnchorPoint(ccp(0,0));
		tile1->setPosition(ccp(0,0));
		tile1->visit();
		rt->end();

		CCTexture2D* texture = rt->getSprite()->getTexture();
		ccTexParams tp = {GL_LINEAR, GL_LINEAR, GL_REPEAT, GL_REPEAT};
		texture->setTexParameters(&tp);
		m_SpriteB->setTexture(texture);
		m_SpriteB->setTextureRect(CCRectMake(0, 0, m_MapWidth*64, m_MapHeight*64));
	}
开发者ID:ngoaho91,项目名称:bamboocc,代码行数:20,代码来源:TileMapRender.cpp

示例10: setStageList

void CSharpTollgate::setStageList(const vector<CStage>& stageList, int chapter, int openChapter)
{
	m_stageList = stageList;
	m_chapter = chapter;	
	m_openChapter = openChapter;
	m_tableView->setCountOfCell(stageList.size());
	m_tableView->reloadData();

	CTableViewCell *cell = m_tableView->cellAtIndex(3);
	cell->setPositionX(cell->getPositionX()+115);

	CImageView *name = (CImageView*)(m_ui->findWidgetById("name"));
	CCTexture2D *texture = CCTextureCache::sharedTextureCache()->addImage(CCString::createWithFormat("tollgate/chapter_%d.png",chapter)->getCString());
	if(!texture)
	{
		texture = CCTextureCache::sharedTextureCache()->addImage("tollgate/chapter_1.png");
	}
	name->setTexture(texture);
	name->setTextureRect(CCRectMake(0,0,texture->getContentSize().width,texture->getContentSize().height));
}
开发者ID:54993306,项目名称:Classes,代码行数:20,代码来源:SharpTollgate.cpp

示例11: CCTexture2D

	void UITextInputField::CreateWhiteBack()
	{
		if(m_pWhiteBack != NULL)
		{
			m_pWhiteBack->removeFromParentAndCleanup(true);
			m_pWhiteBack = NULL;
		}

		if(m_pTextInputField == NULL)
		{
			return;
		}

		CCSize dimension = m_pTextInputField->getDimensions();
		int dimensionWidth = dimension.width;
		int dimensionHeight = dimension.height;

		if(dimensionWidth != 0 && dimensionHeight != 0)
		{
			int *pixels = new int[(dimensionWidth + 8) * (dimensionHeight + 8)];
			for (int i=0; i<dimensionWidth+8; ++i) {
				for (int j=0; j<dimensionHeight+8; ++j) {
					//pixels[i][j] = 0xffffffff;
					pixels[i*4+j] = 0xffffffff;
				}
			}

			CCTexture2D *texture = new CCTexture2D();
			texture->initWithData(pixels,
				kCCTexture2DPixelFormat_RGB888,
				1,
				1,
				CCSizeMake(dimensionWidth + 8, dimensionHeight + 8)
				);

			delete[] pixels;

			m_pWhiteBack = CCSprite::createWithTexture(texture);
			texture->release();
		}
	}
开发者ID:niuzb,项目名称:hellopet,代码行数:41,代码来源:UITextInputField.cpp

示例12: initShader

//--------------------------------------------------------
bool CShaderNode::initWithVertex( const char* image,const char *vert, const char *frag)
{
	initShader(vert,frag);
	CCTexture2D* pTex = CCTextureCache::sharedTextureCache()->addImage( image );
	if( pTex == NULL )
	{
		return false;
	}
	m_pTexture = pTex->getName();

	CCSize winSize = CCDirector::sharedDirector()->getWinSize();
	setContentSize( winSize );//pTex->getContentSize() );
	setPosition(ccp(winSize.width / 2 - getContentSize().width / 2,
		winSize.height / 2 - getContentSize().height / 2 ));

	m_fTime = 0;

	// 开启自更新
	scheduleUpdate();
	return true;
}
开发者ID:Pancho2wang,项目名称:cocos2dx_shader_demo,代码行数:22,代码来源:ShaderNode.cpp

示例13: init

// on "init" you need to initialize your instance
bool kBaseScene::init()
{
    // 0.alloc memory for shared data
    ksd = new kSharedData;
    // common use resource load into memory
    CCTexture2D *pTextureShadow = CCTextureCache::sharedTextureCache()->addImage("yy.png");
    CCSpriteFrame* shadowFrame = CCSpriteFrame::createWithTexture(pTextureShadow, CCRectMake(0, 0, pTextureShadow->getPixelsWide(), pTextureShadow->getPixelsHigh()));
    CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFrame(shadowFrame, "yy.png");
    // test fake data
    // you should init the shared data after login scene
    ksd->rd.rid = 1;
    ksd->rd.mid = 1;
    ksd->rd.x = 0;
    ksd->rd.y = 0;
    ksd->rd.lv = 18;
    // test fake data over
    // 1.make the network connection
    int connectresult=0;
    ks = new kClientSocket;
    connectresult = ks->start("127.0.0.1", 8810);
    
    if(connectresult == SOCKET_ERROR)
    {
        // to information and exit
        CCMessageBox("wrong", "Error connect to net,check your configuration plz");
        delete ks;
        ks = NULL;
    }
    else
    {
        
    }
    // 2.run base ui manager
    kuimgr = kUiManager::create();
    kuimgr->setTag(CLOSEABLE_LAYER_Z);
    // frame view add
    this->addChild(kuimgr,CLOSEABLE_LAYER_Z);
    
    // 3.net work msg receive loop
    this->schedule(schedule_selector(kBaseScene::onupdate),0.04);
    
    // 4.create the gameview base layer
    gameview = kGameView::create();
    this->addChild(gameview,GAMELAYER_Z);
    // should start login view here,and from login view call relate initview function to
    // load view
    // here.run base scene from role data for test
    kSceneInterface* normapScene = kNormalMapScene::create();
    char mapid[16];
    sprintf(mapid,"map/%d", ksd->rd.mid);
    gameview->changeScene(normapScene,mapid);
    return true;
}
开发者ID:kaelliu,项目名称:IosTestLib,代码行数:54,代码来源:kBaseScene.cpp

示例14: CCRect

 // Loads a texture frame from a file
 CCSpriteFrame *CocosTile::loadSpriteFrame(std::string filename)
 {
     // First attempt to get it from the frame cache, in case it was already loaded from an atlas
     CCSpriteFrame *retVal = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(filename.c_str());
     
     // If not found, create the frame by loading texture
     if (!retVal)
     {
         CCTexture2D *frameTexture = CCTextureCache::sharedTextureCache()->addImage(filename.c_str());
         if (frameTexture)
         {
             retVal = CCSpriteFrame::frameWithTexture(frameTexture, 
                                                      CCRect(0, 0, frameTexture->getContentSize().width, frameTexture->getContentSize().height));
             
             // Add to frame cache
             CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFrame(retVal, filename.c_str());
         }
     }
     
     return retVal;        
 }
开发者ID:Avnerus,项目名称:ichigo,代码行数:22,代码来源:CocosTile.cpp

示例15: CC_CONTENT_SCALE_FACTOR

//-------------------------------------------------------------------------
bool FKCW_UI_ProgressIndicator::initWithMessage(const string& message)
{
	if(!CCLayerColor::initWithColor(m_tagDimColor)) 
	{
		return false;
	}

	// 保存消息
	m_strMessage = message;

	// 创建Label
	m_pMsgLabel = CCLabelTTF::create(m_strMessage.c_str(),
		"Helvetica",
		28 / CC_CONTENT_SCALE_FACTOR());

	// 提示器
	CCImage* image = new CCImage();
	image->initWithImageData((void*)s_SpinnerPng, 1043);
	CCTexture2D* tex = new CCTexture2D();
	tex->initWithImage(image);
	m_pIndicator = CCSprite::createWithTexture(tex);
	CC_SAFE_RETAIN(m_pIndicator);
	image->release();
	tex->release();

	_RelayOut();
	addChild(m_pIndicator);
	addChild(m_pMsgLabel);

	// 开启事件
	setTouchEnabled(true);
	setTouchMode(kCCTouchesOneByOne);
	setTouchPriority(-MAX_INT);
	setKeypadEnabled(true);

	// 开启帧更新
	scheduleUpdate();
	
	return true;
}
开发者ID:duzhi5368,项目名称:FKCocos2dxWrapper_2.x,代码行数:41,代码来源:FKCW_UI_ProgressIndicator.cpp


注:本文中的CCTexture2D类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。