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


C++ CCTexture2D::getContentSize方法代码示例

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


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

示例1: hitAnimation

/* AnimatioinクラスhitAnimation関数定義
 * 返却型 : CCFiniteTimeAction
 * 仮引数 : int型変数count
 */
CCFiniteTimeAction* Animation::hitAnimation(int count) {
	CCDelayTime* delay = CCDelayTime::create(4);		//2秒ディレイ test用
	CCArray *animFrames = CCArray::create();			//CCArray型配列を初期化
	CCSpriteFrameCache *cache = CCSpriteFrameCache::sharedSpriteFrameCache();	//キャッシュより指定したファイル名のインスタンスを取得しCCSpriteFrame型のオブジェクトframeに代入
	/* 初期値0のint型変数iが
	 * count未満の間
	 * インクリメント
	 */
	for(int i=0; i<count; i++) {
		CCString* fileName =
				CCString::createWithFormat(count == 14 ? "hit%d.png" : "defeat%d.png", i);	//countが13と同値であればhit%d.pngの、違う場合はdefeat%d.pngのファイルネームを取得しfileNameに代入
		CCSpriteFrame *frame = cache->spriteFrameByName(fileName->getCString());	//キャッシュからインスタンスを取得

		//インスタンスが取得できない場合(初回読み込み時まだインスタンスが生成されていない為)
		if(!frame) {
			CCTexture2D *texture = CCTextureCache::sharedTextureCache()->addImage(fileName->getCString());			//fileNameに一致するファイルの取得
			CCRect bounds = CCRectMake(0, 0, texture->getContentSize().width, texture->getContentSize().height);	//インスタンスの座標とサイズを取得
			frame = CCSpriteFrame::createWithTexture(texture, bounds);	//テクスチャをframeに代入
		}
		animFrames->addObject(frame);	//インスタンスを配列に追加
	}
	CCAnimation* animation = CCAnimation::createWithSpriteFrames(animFrames, 0.1);	//CCSpriteFrameCacheクラスの配列を引数にCCAnimationクラスのインスタンスの生成 第二引数は1フレームの時間

	return CCAnimate::create(animation);	//CCAnimateクラスのアクションを生成して返却
}
开发者ID:usseeebaaaka,项目名称:sensuikan,代码行数:29,代码来源:Animation.cpp

示例2: init

bool ItemLadderLR::init(CCDictionary* dict)
{
	Item::init();
	_type = Item::IT_LadderLR;

	setPositionByProperty(dict);

	// 梯子的显示
	CCTexture2D* texture = CCTextureCache::sharedTextureCache()->addImage("ladder.png");
	setTexture(texture);
	setTextureRect(CCRectMake(0, 0, texture->getContentSize().width, texture->getContentSize().height));

	Common::moveNode(this, ccp(-texture->getContentSize().width / 2, 0));

	// 属性
	_LorR = 1-dict->valueForKey("LorR")->intValue();  // 一开始向左还是向右
	_ladderDis = dict->valueForKey("ladderDis")->intValue();  // 摆动的幅度

	// 梯子一个回合已经移动过的距离
	_dis = 0;
	// 梯子移动速度
	_speed = 20;
	// 标记mario在我这个梯子上
	_marioOnThisLadder = false;

	return true;
}
开发者ID:dalechngame,项目名称:mygame,代码行数:27,代码来源:ItemLadderLR.cpp

示例3: replaceTexture

void Image::replaceTexture(const char* filename, bool keepExactSize, bool async, bool keepRatio)
{
    if(async)
    {
        //Note : async will be done on next update to avoid the performance drop because of the overhead of addImageAsync,
        //and in case the image already exists (which loads the image synchronously)
        loadingImageFile = filename;
        loadingKeepExactSize = keepExactSize;
        loadingKeepRatio = keepRatio;
    }
    else
    {
        std::string originalImageFile = imageFile;
        imageFile = filename;
        CCSprite* sprite = (CCSprite*)this->getNode();
        CCSize initialSize = CCSizeMake(sprite->getContentSize().width * sprite->getScaleX(), sprite->getContentSize().height * sprite->getScaleY());
        CCTexture2D* newTexture = CCTextureCache::sharedTextureCache()->addImage(imageFile.append(".png").c_str());
        imageFile.erase(imageFile.length() - 4, 4);
        if(newTexture == NULL)
        {
            newTexture = CCTextureCache::sharedTextureCache()->addImage(imageFile.append(".jpg").c_str());
            imageFile.erase(imageFile.length() - 4, 4);
        }
        if(newTexture == NULL)
        {
#if VERBOSE_WARNING
            CCLog("Warning : Problem with asset : %s, texture not replaced", filename);
#endif
            imageFile = originalImageFile;
            return;
        }
        sprite->setTexture(newTexture);
        CCRect textureRect = CCRectMake(0, 0, newTexture->getContentSize().width, newTexture->getContentSize().height);
        //Change the textureRect to crop it if necessary
        if(keepRatio && initialSize.width / initialSize.height != textureRect.size.width / textureRect.size.height)
        {
            //initial is wider, crop top and bottom
            if(initialSize.width / initialSize.height > textureRect.size.width / textureRect.size.height)
            {
                float excessHeight = textureRect.size.height - initialSize.height / initialSize.width * textureRect.size.width;
                textureRect.origin.y = excessHeight/2;
                textureRect.size.height -= excessHeight;
            }
            //initial is taller, crop the sides
            else
            {
                float excessWidth = textureRect.size.width - initialSize.width / initialSize.height * textureRect.size.height;
                textureRect.origin.x = excessWidth/2;
                textureRect.size.width -= excessWidth;
            }
        }
        sprite->setTextureRect(textureRect);
        if(keepExactSize)
        {
            sprite->setScale(MIN(initialSize.width / sprite->getContentSize().width,
                                 initialSize.height / sprite->getContentSize().height));
        }
    }
}
开发者ID:nikhildhamsaniya,项目名称:FenneX,代码行数:59,代码来源:Image.cpp

示例4: changeImageByStatus

void Rope::changeImageByStatus(int _status, Hanger * _hanger)
{
	status = _status;
	CCTexture2D *pTexture;
	CCRect rect;
	// 添加根据状态换图的代码 (注意添加这里width 和 height跟随图片的宽高变换)
	switch(status)
	{
	case ROPE_STATUS_NORMAL:
		pTexture = CCTextureCache::sharedTextureCache()->addImage("youxi/shenzi.png");
		if (pTexture)
		{
			rect = CCRectZero;
			rect.size = pTexture->getContentSize();
			setTexture(pTexture);
			setTextureRect(rect);
		}
		lengthOriginal = getContentSize().height * 0.8;
		break;
	case ROPE_STATUS_THROW:
		pTexture = CCTextureCache::sharedTextureCache()->addImage("youxi/shenzi2.png");
		if (pTexture)
		{
			rect = CCRectZero;
			rect.size = pTexture->getContentSize();
			setTexture(pTexture);
			setTextureRect(rect);
		}
		lengthOriginal = getContentSize().height * 0.8;
		scaleExchange = ROPE_EXCHANGE_CONTROL_THROW;
		break;
	case ROPE_STATUS_INTERSECT:
		pTexture = CCTextureCache::sharedTextureCache()->addImage("youxi/shenzi3.png");
		if (pTexture)
		{
			rect = CCRectZero;
			rect.size = pTexture->getContentSize();
			setTexture(pTexture);
			setTextureRect(rect);
		}
		lengthOriginal = getContentSize().height * 0.8;
		break;
	case ROPE_STATUS_PULL:
		pTexture = CCTextureCache::sharedTextureCache()->addImage("youxi/shenzi4.png");
		if (pTexture)
		{
			rect = CCRectZero;
			rect.size = pTexture->getContentSize();
			setTexture(pTexture);
			setTextureRect(rect);
		}
		lengthOriginal = getContentSize().height * 0.8;
		break;
	default:
		break;
	}
	changePosition(_hanger);
}
开发者ID:wjf1616,项目名称:TheMiners,代码行数:58,代码来源:Rope.cpp

示例5: _AtlasPage_createTexture

void _AtlasPage_createTexture (AtlasPage* self, const char* path) {
	CCTexture2D* texture = CCTextureCache::sharedTextureCache()->addImage(path);
	CCTextureAtlas* textureAtlas = CCTextureAtlas::createWithTexture(texture, 4);
	textureAtlas->retain();
	self->rendererObject = textureAtlas;
    // Using getContentSize to make it supports the strategy of loading resources in cocos2d-x.
	// self->width = texture->getPixelsWide();
	// self->height = texture->getPixelsHigh();
    self->width = texture->getContentSize().width;
    self->height = texture->getContentSize().height;
}
开发者ID:0309,项目名称:cocos2d-x,代码行数:11,代码来源:spine-cocos2dx.cpp

示例6: startProcess

void UICenterItem::startProcess()
{
	valid = false;
	// 创建一个动画 自身播放时间到后将valid 设置为true
	CCAnimation* animation = CCAnimation::create();
		std::string frameNames[] = {
			std::string("skill_p_00000.png"),
			std::string("skill_p_00001.png"),
			std::string("skill_p_00002.png"),
			std::string("skill_p_00003.png"),
			std::string("skill_p_00004.png"),
			std::string("skill_p_00005.png"),
		};
	for (int i = 0; i < 3; i++)
	{
		CCTexture2D *texture = CCTextureCache::sharedTextureCache()->addImage(frameNames[i].c_str());
		
		CCSpriteFrame *frame = CCSpriteFrame::frameWithTexture(texture,CCRectMake(0,0,texture->getContentSize().width,texture->getContentSize().height));
		
		animation->addSpriteFrame(frame);
	}
	CCSprite * temp = CCSprite::create();
	this->getParent()->addChild(temp);
	temp->setPosition(this->getPosition());
	animation->setDelayPerUnit(1.5f / 2);
	animation->setRestoreOriginalFrame(true);
	temp->runAction(CCSequence::create(CCAnimate::create(animation),
		CCCallFuncND::create(this, callfuncND_selector(UICenterItem::actionEnd_setValid), (void*)temp),NULL));

}
开发者ID:coderHsc,项目名称:sygame,代码行数:30,代码来源:UICenterBag.cpp

示例7: 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;
}
开发者ID:Whislly,项目名称:DreamBookToolbox,代码行数:30,代码来源:ToyLayer.cpp

示例8: init

bool HeXieBag::init(const CCSize &size,const char *pngName)
{
	this->_eachHeight = 64;
	this->_eachWidth = 64;
	this->_width = size.width;
	this->_height = size.height;
	_items.resize(this->_width* this->_height);
	_eachLeftSpan = 1;
	_eachUpSpan = 1;
	// 将图片打乱放置于BAG上
	CCTexture2D *pTexture = CCTextureCache::sharedTextureCache()->addImage(pngName);
	CCSize imgSize = pTexture->getContentSize();
	eachSize = CCSizeMake(imgSize.width / this->_width,imgSize.height / this->_height);
	for (int i = 0; i < size.width ;i++)
		for (int j = 0; j < size.height;j++)
		{
			HeXieItem*item = HeXieItem::create(pTexture,
				CCRectMake(i * eachSize.width,j * eachSize.height,eachSize.width,eachSize.height));
			int id =  (size.height - j -1) * size.width + i;
			this->setItem(item,id);
			item->positionId = id;
		}
	show();
	return true;
}
开发者ID:coderHsc,项目名称:sygame,代码行数:25,代码来源:HeXieItem.cpp

示例9:

CCSpriteFrame * UICenterItem::getFrameByFileName(const char *pngName)
{
	CCTexture2D *texture = CCTextureCache::sharedTextureCache()->addImage(pngName);
		
	CCSpriteFrame *frame = CCSpriteFrame::frameWithTexture(texture,CCRectMake(0,0,texture->getContentSize().width,texture->getContentSize().height));
	return frame;
}
开发者ID:coderHsc,项目名称:sygame,代码行数:7,代码来源:UICenterBag.cpp

示例10: 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;
}
开发者ID:Whislly,项目名称:DreamBookToolbox,代码行数:35,代码来源:DancingBoneLayer.cpp

示例11: addFrameWithFileName

	void CCAnimation::addFrameWithFileName(const char *pszFileName)
	{
		CCTexture2D *pTexture = CCTextureCache::sharedTextureCache()->addImage(pszFileName);
		CCRect rect = CCRectZero;
		rect.size = pTexture->getContentSize();
		CCSpriteFrame *pFrame = CCSpriteFrame::frameWithTexture(pTexture, rect);
		m_pobFrames->addObject(pFrame);
	}
开发者ID:ccjimmy,项目名称:TweeJump4wp8,代码行数:8,代码来源:CCAnimation.cpp

示例12: init

bool ItemFlagPoint::init(CCDictionary* dict)
{
	Item::init();
	_Flag = this;

	_type = Item::IT_flagpoint;

	setPositionByProperty(dict);

	CCTexture2D* texture = CCTextureCache::sharedTextureCache()->addImage("flag.png");
	setTexture(texture);
	setTextureRect(CCRect(0, 0, texture->getContentSize().width, texture->getContentSize().height));

	Common::moveNode(this, ccp(-texture->getContentSize().width / 2, 0));

	return true;
}
开发者ID:dalechngame,项目名称:mygame,代码行数:17,代码来源:ItemFlagPoint.cpp

示例13: createRope

void VRope::createRope(cocos2d::CCPoint pointA, cocos2d::CCPoint pointB, float ropeLenght) {
    
    float distance;
    if (ropeLenght < 0) {
        distance = ccpDistance(pointA,pointB);
    }else{
        distance = ropeLenght;
    }
    
	int segmentFactor = RopeSegmentFactor; //increase value to have less segments per rope, decrease to have more segments
	numPoints = distance/segmentFactor;
    
    mRopeLength = segmentFactor * numPoints;
    
	CCPoint diffVector = ccpSub(pointB,pointA);
	float multiplier = distance / (numPoints-1);
	antiSagHack = 0.1f; //HACK: scale down rope points to cheat sag. set to 0 to disable, max suggested value 0.1
    
	for(int i=0;i<numPoints;i++) {
		CCPoint tmpVector = ccpAdd(pointA, ccpMult(ccpNormalize(diffVector),multiplier*i*(1-antiSagHack)));
		VPoint* tmpPoint = new VPoint;
        tmpPoint->setPos(tmpVector.x, tmpVector.y);
        vPoints.insert(vPoints.end(), tmpPoint);
	}
    
	for(int i=0;i<numPoints-1;i++) {
        VStick tmpStick;
        tmpStick.initWith(vPoints[i], vPoints[i+1]);
		vSticks.insert(vSticks.end(), tmpStick);
	}
    
	if(spriteSheet!=NULL) {
		for(int i=0;i<numPoints-1;i++) {
            VPoint* point1 = vSticks[i].getPointA();
            VPoint* point2 = vSticks[i].getPointB();
			CCPoint stickVector = ccpSub(ccp(point1->x,point1->y),ccp(point2->x,point2->y));
			float stickAngle = ccpToAngle(stickVector);
            
            CCTexture2D* texture = spriteSheet->getTexture();
            RecordSprite* tmpSprite = new RecordSprite;
			tmpSprite->setTag(Tag_Box_RopeBatchSprite);
			tmpSprite->autorelease();
			tmpSprite->initWithTexture(texture, CCRectMake(0,0,multiplier,texture->getContentSize().height));
			ccTexParams params = {GL_LINEAR,GL_LINEAR,GL_REPEAT,GL_REPEAT};
            tmpSprite->getTexture()->setTexParameters(&params);
            tmpSprite->setPosition(ccpMidpoint(ccp(point1->x,point1->y),ccp(point2->x,point2->y)));
            tmpSprite->setRotation(-1 * CC_RADIANS_TO_DEGREES(stickAngle));
            spriteSheet->addChild(tmpSprite);
            ropeSprites.insert(ropeSprites.end(), tmpSprite);
		}

		//// LiFeng 添加
		//ropeSprites[ropeSprites.size()-1]->setOpacity(100);
	}else{
        CCAssert(false, "not init");
    }
    
}
开发者ID:SongCF,项目名称:game-LostStar,代码行数:58,代码来源:VRope.cpp

示例14: setImagePath

void MyTableViewCell::setImagePath(const char* path)
{
    CCTexture2D *tex = CCTextureCache::sharedTextureCache()->addImage(path);
    m_imageSprite->setTexture(tex);
    CCSize contentSize = tex->getContentSize();
    m_imageSprite->setTextureRect(CCRectMake(0, 0,
                                             contentSize.width, contentSize.height));
    needsLayout();
}
开发者ID:DPigpen,项目名称:cocos2dx_recipe,代码行数:9,代码来源:MyTableViewCell.cpp

示例15: showImmediately

void AchievementNotification::showImmediately(Achievement a)
{
	mShowing = true;
	CCTexture2D* tex = CCTextureCache::sharedTextureCache()->textureForKey(fileName.c_str());
	if (tex == NULL)
	{
		tex = CCTextureCache::sharedTextureCache()->addImage(fileName.c_str());
	}
	CCSize winSize = CCDirector::sharedDirector()->getWinSize();


	CCScale9Sprite* pBoard = CCScale9Sprite::create(CCRectMake(tex->getContentSize().width/2, 0, 2, tex->getContentSize().height), fileName.c_str());
	addChild(pBoard,0,Tag_Board);
	pBoard->setPosition(ccp(winSize.width/2,winSize.height + pBoard->getContentSize().height) );

	CCSprite* pJinBei = CCSprite::create(ResManager::getManager()->getFilePath(g_public+"CJ_icon_jiangbei.png").c_str());
	pBoard->addChild(pJinBei, 1);
	pJinBei->setPosition(ccp(pJinBei->getContentSize().width, pBoard->getContentSize().height/2));

	CCLabelTTF* pName = CCLabelTTF::create(a.name.c_str(), fontStr_KlavikaBold, 40);
	pName->setColor(fontColor_Acheivement_TTF);
	CCSprite* pIcon = CCSprite::create(ResManager::getManager()->getFilePath(g_public+"CJ_icon_wancheng.png").c_str());
	int x = pName->getContentSize().width + pIcon->getContentSize().width - 420;
	if (x > 0)
	{
		pBoard->setContentSize(ccp(pBoard->getContentSize().width+x, pBoard->getContentSize().height));
	}
	pBoard->addChild(pName);

	int xoffset = 10;

	pName->setPosition(ccp(pBoard->getContentSize().width/2 + pIcon->getContentSize().width/2 + xoffset, pBoard->getContentSize().height/2));

	pBoard->addChild(pIcon);
	pIcon->setPosition(ccp(pName->getPositionX() - pName->getContentSize().width/2 - pIcon->getContentSize().width/2 - xoffset, pName->getPositionY()));

	Achievement* achievementCopy = new Achievement(a);
//	*achievementCopy = a;
	temp_Must_Delete.insert(temp_Must_Delete.end(),achievementCopy);

	pBoard->runAction(CCSequence::create(
		CCMoveTo::create(0.5f,ccp(pBoard->getPositionX(),winSize.height-pBoard->getContentSize().height/2)),
		CCDelayTime::create(0.1f),
		CCCallFuncND::create(this,SEL_CallFuncND(&AchievementNotification::boardShowing),achievementCopy),
		CCDelayTime::create(1.3f),
		CCMoveTo::create(0.2f,ccp(pBoard->getPositionX(),winSize.height+pBoard->getContentSize().height)),
		CCFadeTo::create(0.1f,0),
		CCCallFuncN::create(this,SEL_CallFuncN(&AchievementNotification::boardShowEnd)),NULL));

	createPar(ccp(winSize.width/2,winSize.height),parFileName.c_str(),pBoard->getContentSize().width * 1.2f,pBoard->getContentSize().height);

	Music::sharedMusicPlayer()->playEffectSound("achievement.wav");

	CCLog("AchievementNotification::showImmediately name = %s" ,a.name.c_str());
}
开发者ID:SongCF,项目名称:game-LostStar,代码行数:55,代码来源:AchievementNotification.cpp


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