本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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));
}
示例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;
}
示例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;
}
示例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));
}
示例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));
}
示例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();
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}