本文整理汇总了C++中CCClippingNode::addChild方法的典型用法代码示例。如果您正苦于以下问题:C++ CCClippingNode::addChild方法的具体用法?C++ CCClippingNode::addChild怎么用?C++ CCClippingNode::addChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCClippingNode
的用法示例。
在下文中一共展示了CCClippingNode::addChild方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Init
bool Background::Init()
{
do
{
CCNodeLoaderLibrary * ccNodeLoaderLibraryLeft = CCNodeLoaderLibrary::newDefaultCCNodeLoaderLibrary();
CCBReader * ccbReaderLeft = new CCBReader(ccNodeLoaderLibraryLeft);
CCNode * bgLeft = ccbReaderLeft->readNodeGraphFromFile("ccb/background.ccbi", this);
CCBAnimationManager* animationManagerLeft = ccbReaderLeft->getAnimationManager();
animationManagerLeft->runAnimationsForSequenceNamed("left");
ccbReaderLeft->release();
CCNodeLoaderLibrary * ccNodeLoaderLibraryRight = CCNodeLoaderLibrary::newDefaultCCNodeLoaderLibrary();
CCBReader * ccbReaderRight = new CCBReader(ccNodeLoaderLibraryRight);
CCNode * bgRight = ccbReaderRight->readNodeGraphFromFile("ccb/background.ccbi", this);
CCBAnimationManager* animationManagerRight = ccbReaderRight->getAnimationManager();
animationManagerRight->runAnimationsForSequenceNamed("right");
ccbReaderRight->release();
CCClippingNode * clippingNodeLeft = CCClippingNode::create();
addChild(clippingNodeLeft);
clippingNodeLeft->addChild(bgLeft,enZOrderBack,enTagBgLeft);
CCDrawNode *shapeLeft = CCDrawNode::create();
static CCPoint triangleLeft[3];
triangleLeft[0] = ccp(0, 0);
triangleLeft[1] = ccp(SCREEN_WIDTH,0);
triangleLeft[2] = ccp(0,SCREEN_HEIGHT);
static ccColor4F green = {0, 1, 0, 1};
shapeLeft->drawPolygon(triangleLeft, 3, green, 0, green);
clippingNodeLeft->setStencil(shapeLeft);
clippingNodeLeft->setInverted(false);
CCClippingNode * clippingNodeRight = CCClippingNode::create();
addChild(clippingNodeRight);
clippingNodeRight->addChild(bgRight,enZOrderBack,enTagBgRight);
CCDrawNode *shapeRight = CCDrawNode::create();
static CCPoint triangleRight[3];
triangleRight[0] = ccp(SCREEN_WIDTH, SCREEN_HEIGHT);
triangleRight[1] = ccp(SCREEN_WIDTH,0);
triangleRight[2] = ccp(0,SCREEN_HEIGHT);
// static ccColor4F green = {0, 1, 0, 1};
shapeRight->drawPolygon(triangleRight, 3, green, 0, green);
clippingNodeRight->setStencil(shapeRight);
clippingNodeRight->setInverted(false);
m_CraterArrayLeft = CCArray::create();
m_CraterArrayLeft->retain();
m_CraterArrayRight = CCArray::create();
m_CraterArrayRight->retain();
m_CraterArrayLeftDeleted = CCArray::create();
m_CraterArrayLeftDeleted->retain();
m_CraterArrayRightDeleted = CCArray::create();
m_CraterArrayRightDeleted->retain();
return true;
} while (false);
CCLog("Function Background::Init Error!");
return false;
}
示例2: init
bool OptionLayer::init() {
if (!CCLayer::init()) {
return false;
}
_back = CCSprite::create("back.png");
_back->setPosition(ccp(24 + 40, 800 - 56.5 + 15));
this->addChild(_back);
CCSprite * mode = CCSprite::create("mode.png");
mode->setPosition(ccp(132 + 111, 800 - 103 - 19.5));
this->addChild(mode);
CCSpriteBatchNode* batchNode = CCSpriteBatchNode::create("dotted_line.png");
int dottedLineY[3] = {313, 420, 539};
for (int i = 0; i < 3; i++) {
CCSprite * dotLine = CCSprite::createWithTexture(batchNode->getTexture());
dotLine->setPosition(ccp(27 + 210.5, 800 - dottedLineY[i] - 1.5));
this->addChild(dotLine);
}
_switchIndex = -1;
_switches[0] = &Settings::showConflictedDigit;
_switches[1] = &Settings::musicEnabled;
_switches[2] = &Settings::soundEnabled;
_switches[3] = &Settings::preventSleeping;
_switches[4] = &Settings::showTimer;
_switches[5] = &Settings::autoHighLight;
_switches[6] = &Settings::autoRemoveNotes;
_switches[7] = &Settings::removeCompleteDigits;
CCSpriteBatchNode* maskBatchNode = CCSpriteBatchNode::create("mask.png");
CCSpriteBatchNode* switchBatch = CCSpriteBatchNode::create("switch.png");
_switchButtons = CCArray::createWithCapacity(7);
_switchButtons->retain();
char opLabel[10];
int opLabelY[8] = {271, 332, 379, 445, 492, 566, 612, 657};
for(int i = 0; i < 8; i++) {
sprintf(opLabel, "op%d.png", i);
CCSprite * label = CCSprite::create(opLabel);
label->setPosition(ccp(25 + label->boundingBox().size.width / 2,
800 - opLabelY[i] - label->boundingBox().size.height / 2));
this->addChild(label);
CCSprite * stencil = CCSprite::createWithTexture(maskBatchNode->getTexture());
stencil->setPosition(ccp(380 + 39, 800 - opLabelY[i] - label->boundingBox().size.height / 2));
CCClippingNode * cliper = CCClippingNode::create(stencil);
cliper->setAlphaThreshold(0);
CCSprite * switchButton = CCSprite::createWithTexture(switchBatch->getTexture());
switchButton->setPosition(ccp(*(_switches[i]) ? 394 + 49 : 394, 800 - opLabelY[i] - label->boundingBox().size.height / 2));
_switchButtons->addObject(switchButton);
cliper->addChild(switchButton);
this->addChild(cliper);
}
this->setTouchEnabled(true);
this->setKeypadEnabled(true);
return true;
}
示例3: setup
void ScrollViewDemo::setup()
{
CCClippingNode *clipper = CCClippingNode::create();
clipper->setTag( kTagClipperNode );
clipper->setContentSize( CCSizeMake(200, 200) );
clipper->setAnchorPoint( ccp(0.5, 0.5) );
clipper->setPosition( ccp(this->getContentSize().width / 2, this->getContentSize().height / 2) );
clipper->runAction(CCRepeatForever::create(CCRotateBy::create(1, 45)));
this->addChild(clipper);
CCDrawNode *stencil = CCDrawNode::create();
CCPoint rectangle[4];
rectangle[0] = ccp(0, 0);
rectangle[1] = ccp(clipper->getContentSize().width, 0);
rectangle[2] = ccp(clipper->getContentSize().width, clipper->getContentSize().height);
rectangle[3] = ccp(0, clipper->getContentSize().height);
ccColor4F white = {1, 1, 1, 1};
stencil->drawPolygon(rectangle, 4, white, 1, white);
clipper->setStencil(stencil);
CCSprite *content = CCSprite::create(s_back2);
content->setTag( kTagContentNode );
content->setAnchorPoint( ccp(0.5, 0.5) );
content->setPosition( ccp(clipper->getContentSize().width / 2, clipper->getContentSize().height / 2) );
clipper->addChild(content);
m_bScrolling = false;
this->setTouchEnabled(true);
}
示例4: initData
bool UIMakeProgress::initData(const char* fileName, const char* actionName)
{
//init game Data
//元素遮罩
CCSprite* maskSprite = CCSprite::createWithSpriteFrameName(fileName);
m_progressSprite = CCSprite::createWithSpriteFrameName(fileName);
//血条开始位置和最后位置
m_spriteStartPos = maskSprite->getPositionX() - maskSprite->getContentSize().width/2;
m_spriteEndPos = maskSprite->getPositionX() + maskSprite->getContentSize().width/2;
//血量上的动作
CCSprite* m_actionSprite = CCSprite::createWithSpriteFrameName(actionName);
m_actionSprite->setPosition(ccp(m_progressSprite->getContentSize().width/2, m_progressSprite->getContentSize().height/2));
m_actionSprite->setColor(ccc3(108, 249, 206));
m_actionSprite->setOpacity(0);
m_actionSprite->setTag(0);
m_progressSprite->addChild(m_actionSprite);
// this->addChild(m_progressSprite);
CCClippingNode* clip =CCClippingNode::create();
//设定遮罩层
clip->setStencil(maskSprite);
//设定被遮罩层
clip->addChild(m_progressSprite);
//将ClippingNode放置到舞台显示
this->addChild(clip);
//设定遮罩图层的透明度取值范围
clip->setAlphaThreshold(0);
//设定遮罩的模式true显示没有被遮起来的纹理
//如果是false就显示遮罩起来的纹理
//clip是一个显示对象(容器)
clip->setInverted(false);
return true;
}
示例5: ccp
bool Recipe26::init()
{
if ( !RecipeBase::init() )
{
return false;
}
CCSize size = CCDirector::sharedDirector()->getVisibleSize();
CCSprite* pSprite = CCSprite::create("HelloWorld.png");
pSprite->setPosition( ccp(size.width/2, size.height/2) );
CCSprite* pMask = CCSprite::create("mask_star.png");
pMask->setPosition(ccp(size.width/2, size.height/2));
CCClippingNode* pClip = CCClippingNode::create();
pClip->setStencil(pMask);
pClip->setAlphaThreshold(0.0f);
pClip->addChild(pSprite);
this->addChild(pClip);
return true;
}
示例6: attachToUIScrollView
void CCScrollBar::attachToUIScrollView(ScrollView* scrollView, ccInsets insets, bool horizontal) {
// save flag
m_horizontal = horizontal;
// add to scroll view
float thumbLength = 0;
Widget* svParent = dynamic_cast<Widget*>(scrollView->getParent());
CCSize svSize = scrollView->getSize();
CCPoint svOrigin = CCUtils::getOrigin(scrollView);
CCSize innerSize = scrollView->getInnerContainerSize();
CCSize sbSize;
if(horizontal) {
sbSize = CCSizeMake(m_track->getContentSize().width,
svSize.width - insets.left - insets.right);
setContentSize(sbSize);
setAnchorPoint(ccp(0, 0.5f));
setPosition(ccp(svOrigin.x + svSize.width / 2,
svOrigin.y + insets.bottom));
setRotation(-90);
svParent->addNode(this, MAX_INT);
// thumb length
if(m_fixedThumb)
thumbLength = m_fixedThumb->getContentSize().height;
else
thumbLength = MIN(1, svSize.width / innerSize.width) * sbSize.height;
} else {
sbSize = CCSizeMake(m_track->getContentSize().width,
svSize.height - insets.top - insets.bottom);
setContentSize(sbSize);
setAnchorPoint(ccp(1, 0.5f));
setPosition(ccp(svOrigin.x + svSize.width - insets.right,
svOrigin.y + svSize.height / 2));
svParent->addNode(this, MAX_INT);
// thumb length
if(m_fixedThumb)
thumbLength = m_fixedThumb->getContentSize().height;
else
thumbLength = MIN(1, svSize.height / innerSize.height) * sbSize.height;
}
// add track
m_track->setPreferredSize(sbSize);
m_track->setPosition(CCUtils::getLocalCenter(this));
addChild(m_track);
// clipping node to hold thumb
CCClippingNode* thumbClipping = CCClippingNode::create(m_track);
thumbClipping->ignoreAnchorPointForPosition(false);
thumbClipping->setAnchorPoint(ccp(0.5f, 0.5f));
thumbClipping->setContentSize(sbSize);
thumbClipping->setPosition(CCUtils::getLocalCenter(this));
thumbClipping->setAlphaThreshold(0.5f);
thumbClipping->setScaleX((sbSize.width - 4) / sbSize.width);
thumbClipping->setScaleY((sbSize.height - 4) / sbSize.height);
addChild(thumbClipping);
// thumb or fixed thumb
if(m_thumb) {
m_thumb->setPreferredSize(CCSizeMake(sbSize.width, thumbLength));
m_thumb->setPosition(ccp(sbSize.width / 2,
sbSize.height - thumbLength / 2));
thumbClipping->addChild(m_thumb);
} else {
m_fixedThumb->setPosition(ccp(sbSize.width / 2,
sbSize.height - thumbLength / 2));
thumbClipping->addChild(m_fixedThumb);
}
// sync thumb position
syncThumbPositionForUIScrollView(scrollView);
// listen to scrollview scrolling event
scrollView->addEventListenerScrollView(this, scrollvieweventselector(CCScrollBar::onUIScrollViewEvent));
// init fade out
if(m_initFadeOut) {
m_fadingOut = true;
CCUtils::setOpacityRecursively(this, 0);
}
}
示例7: attachToCCScrollView
void CCScrollBar::attachToCCScrollView(CCScrollView* scrollView, ccInsets insets, bool horizontal) {
// it must have parent node
CCNode* svParent = scrollView->getParent();
if(!svParent) {
CCLOGWARN("CCScrollView must be added to one node before calling attachToCCScrollView");
return;
}
// save flag
m_horizontal = horizontal;
// add to scroll view
float thumbLength = 0;
CCPoint svOrigin = CCUtils::getOrigin(scrollView);
CCSize svSize = scrollView->getViewSize();
CCSize innerSize = scrollView->getContainer()->getContentSize();
CCSize sbSize;
if(horizontal) {
sbSize = CCSizeMake(m_track->getContentSize().width,
svSize.width - insets.left - insets.right);
setContentSize(sbSize);
setAnchorPoint(ccp(0, 0.5f));
setPosition(ccp(svOrigin.x + svSize.width / 2, svOrigin.y + insets.bottom));
setRotation(-90);
UIWidget* svpWidght = dynamic_cast<UIWidget*>(svParent);
if(svpWidght)
svpWidght->addNode(this, MAX_INT);
else
svParent->addChild(this, MAX_INT);
// thumb length
if(m_fixedThumb)
thumbLength = m_fixedThumb->getContentSize().height;
else
thumbLength = MIN(1, svSize.width / innerSize.width) * sbSize.height;
} else {
sbSize = CCSizeMake(m_track->getContentSize().width,
svSize.height - insets.top - insets.bottom);
setContentSize(sbSize);
setAnchorPoint(ccp(1, 0.5f));
setPosition(ccp(svOrigin.x + svSize.width - insets.right, svOrigin.y + svSize.height / 2));
UIWidget* svpWidght = dynamic_cast<UIWidget*>(svParent);
if(svpWidght)
svpWidght->addNode(this, MAX_INT);
else
svParent->addChild(this, MAX_INT);
// thumb length
if(m_fixedThumb)
thumbLength = m_fixedThumb->getContentSize().height;
else
thumbLength = MIN(1, svSize.height / innerSize.height) * sbSize.height;
}
// add track
m_track->setPreferredSize(sbSize);
m_track->setPosition(CCUtils::getLocalCenter(this));
addChild(m_track);
// clipping node to hold thumb
CCClippingNode* thumbClipping = CCClippingNode::create(m_track);
thumbClipping->ignoreAnchorPointForPosition(false);
thumbClipping->setAnchorPoint(ccp(0.5f, 0.5f));
thumbClipping->setContentSize(sbSize);
thumbClipping->setPosition(CCUtils::getLocalCenter(this));
thumbClipping->setAlphaThreshold(0.5f);
thumbClipping->setScaleX((sbSize.width - 4) / sbSize.width);
thumbClipping->setScaleY((sbSize.height - 4) / sbSize.height);
addChild(thumbClipping);
// thumb or fixed thumb
if(m_thumb) {
m_thumb->setPreferredSize(CCSizeMake(sbSize.width, thumbLength));
m_thumb->setPosition(ccp(sbSize.width / 2,
sbSize.height - thumbLength / 2));
thumbClipping->addChild(m_thumb);
} else {
m_fixedThumb->setPosition(ccp(sbSize.width / 2,
sbSize.height - thumbLength / 2));
thumbClipping->addChild(m_fixedThumb);
}
// sync thumb position
syncThumbPositionForCCScrollView(scrollView);
// delegate
m_oldCCDelegate = scrollView->getDelegate();
scrollView->setDelegate(this);
// init fade out
if(m_initFadeOut) {
m_fadingOut = true;
CCUtils::setOpacityRecursively(this, 0);
}
}
示例8: init
bool TipsScene::init()
{
if ( !CCLayer::init())
{
return false;
}
CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
mCallFunc = NULL;
targetRidus = 100;
//创建一个遮罩层。
CCLayerColor* pLayer;
if (isHasTarget && !istouchRemove)
{
pLayer=CCLayerColor::create(ccc4(0,0,0,200));
/*创建剪裁节点*/
CCClippingNode* pClip = CCClippingNode::create() ;
pClip->setInverted(true) ;//设置是否反向,将决定画出来的区域是透明的还是黑色的。
this->addChild(pClip) ;
/*注意将LayerColor层添加到剪裁节点上*/
pClip->addChild(pLayer) ;
//模板
CCDrawNode* pStencil = CCDrawNode::create() ;
static ccColor4F red = {1,0,0,1} ;
float radius = targetRidus/2 ;
const int nCount = 200 ;
const float angel = 2.0 * (float)M_PI/nCount ;
static CCPoint circle[nCount] ;
for (int i=0; i<nCount; i++) {
float radian = i*angel ; //弧度
circle[i].x = radius * cosf(radian) ;
circle[i].y = radius * sinf(radian) ;
}
pStencil->drawPolygon(circle, nCount, red, 0, red) ;
pStencil->runAction(CCRepeatForever::create(CCSequence::createWithTwoActions(CCScaleBy::create(0.2f, 0.9f), CCScaleTo::create(0.2f, 1)))) ;
pStencil->setPosition(targetPoint);
pClip->setStencil(pStencil) ; //将这个区域从剪裁节点上面抠出来。Stencil是模板的意思
}
else if (shouldPauseGame)
{
pLayer=CCLayerColor::create(ccc4(0,0,0,100));
this->addChild(pLayer) ;
}
else
{
}
if (isAutoRemove)
{
scheduleOnce(schedule_selector(TipsScene::scheduleResumeGame),2.8);
scheduleOnce(schedule_selector(TipsScene::scheduleRemove),3.0f);
}
CCSprite* tipsbg = CCSprite::create("tipbg.png");
//tipsbg -> setPosition(ccp(375,260));
tipsbg -> setPosition(ccp(375,260 + 160));
addChild(tipsbg);
mTipsWord = CCLabelTTF::create("","Arial",20);
mTipsWord -> setColor(ccYELLOW);
//mTipsWord -> setPosition(ccp(400,240));
mTipsWord -> setPosition(ccp(400,240 + 160));
addChild(mTipsWord);
setTouchEnabled(true);
if (shouldPauseGame)
{
BattleManage* pauseLayer = BattleManage::oneself;
pauseLayer -> pauseSchedulerAndActions();
}
return true;
}
示例9: Init
bool MainScene::Init()
{
CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
CCMenuItemImage *pCloseItem = CCMenuItemImage::create(
"CloseNormal.png",
"CloseSelected.png",
this,
menu_selector(MainScene::menuCloseCallback));
pCloseItem->setPosition(ccp(origin.x + visibleSize.width - pCloseItem->getContentSize().width/2 ,
origin.y + pCloseItem->getContentSize().height/2));
CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
pMenu->setPosition(CCPointZero);
this->addChild(pMenu, 1);
CCLabelTTF* pLabel = CCLabelTTF::create("Hello World", "Arial", 24);
pLabel->setPosition(ccp(origin.x + visibleSize.width/2,
origin.y + visibleSize.height - pLabel->getContentSize().height));
this->addChild(pLabel, 1,1);
CCSprite* pSprite = CCSprite::create("HelloWorld.png");
pSprite->setPosition(ccp(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
this->addChild(pSprite, 0);
setTouchEnabled(true);
// /* Create an autorelease CCNodeLoaderLibrary. */
// CCNodeLoaderLibrary * ccNodeLoaderLibrary = CCNodeLoaderLibrary::newDefaultCCNodeLoaderLibrary();
//// ccNodeLoaderLibrary->registerCCNodeLoader("MainScene", MainSceneLayerLoader::loader());
// /* Create an autorelease CCBReader. */
// cocos2d::extension::CCBReader * ccbReader = new cocos2d::extension::CCBReader(ccNodeLoaderLibrary);
// /* Read a ccbi file. */
// CCNode * node = ccbReader->readNodeGraphFromFile("MainScene.ccbi", this);
// m_AnimationManager = ccbReader->getAnimationManager();
// m_AnimationManager->runAnimationsForSequenceNamed("default");
// m_bMenuShow = true;
// ccbReader->release();
// if(node != NULL) {
// this->addChild(node);
// }
// CCFilteredSpriteWithOne* pSpOne = CCFilteredSpriteWithOne::create("Icon-144.png");
// addChild(pSpOne);
// pSpOne->setPosition(ccp(visibleSize.width/2,visibleSize.height/2));
// CCGrayFilter* pF = CCGrayFilter::create(ccc4f(0.2, 0.3, 0.5, 0.1));
// pSpOne->setFilter(pF);
//
// CCFilteredSpriteWithMulti* pSpMulti = CCFilteredSpriteWithMulti::create("Icon-144.png");
// addChild(pSpMulti);
// pSpMulti->setPosition(ccp(visibleSize.width/2,visibleSize.height/4));
// CCHueFilter* pF1 = CCHueFilter::create(240);
// CCSaturationFilter* pF2 = CCSaturationFilter::create(1.5);
// CCBrightnessFilter* pF3 = CCBrightnessFilter::create(-0.4);
// CCArray* pArray = CCArray::create();
// pArray->addObject(pF1);
// pArray->addObject(pF2);
// pArray->addObject(pF3);
// pSpMulti->setFilters(pArray);
// //test setBlendFunc
// ccBlendFunc cbl = { GL_SRC_ALPHA , GL_ONE };
// CCRotateBy * ccRotateBy = CCRotateBy::create(20.0f, 360);
// CCRepeatForever * ccRepeatForever = CCRepeatForever::create(ccRotateBy);
// this->mBurstSprite->runAction(ccRepeatForever);
// pSp->setBlendFunc(cbl);
//test Shader Utils
// ShaderUtils::alphaMask(pSp, "Icon-114.png");
// ShaderUtils::colorHSL(pSp, 120, 60);
m_count = 0;
// CCSprite *sprite = CCSprite::create("Icon-144.png");
// CCSize winSize = CCDirector::sharedDirector()->getWinSize();
// CCTableView* tableView = CCTableView::create(this,ccp(sprite->getContentSize().width*4,sprite->getContentSize().height*4));
// tableView->setDirection(kCCScrollViewDirectionVertical);
// tableView->setPosition(ccp(winSize.width/3,winSize.height/3));
// tableView->setDelegate(this);
// tableView->setVerticalFillOrder(kCCTableViewFillTopDown);
// this->addChild(tableView,0,111);
// tableView->reloadData();
// sprite->release();
//背景图片
CCSprite * background = CCSprite::create("HelloWorld.png");
background->setPosition(ccp(visibleSize.width/2,visibleSize.height/2));
this->addChild(background,0);
//创建一个裁剪节点用来实现遮罩的效果
CCClippingNode * clippingNode = CCClippingNode::create();
this->addChild(clippingNode,1);
//向裁剪节点中加入内容,这里加入的是一个透明的层
CCLayerColor * layer = CCLayerColor::create(ccc4(0,0,0,200));
clippingNode->addChild(layer);
//继续向裁剪节点中加入内容,这里加入的是一个精灵
CCSprite * sprite = CCSprite::create("Icon-144.png");
sprite->setPosition(ccp(visibleSize.width/4,visibleSize.height/2));
clippingNode->addChild(sprite);
//创建模板,裁剪节点将按照这个模板来裁剪区域
//.........这里部分代码省略.........
示例10: init
bool ImageEditLayer::init(){
if (DialogLayer::init()) {
this->setTitle("头像编辑");
CCPoint middle=ccp(286, 154);
CCSize size=CCSizeMake(570,300);
CCClippingNode* clippingNode = CCClippingNode::create();
//设置裁剪区域大小
clippingNode->setContentSize(size);
clippingNode->setAnchorPoint(ccp(0.5, 0.5));
clippingNode->setPosition(middle);
m_contentLayer->addChild(clippingNode);
CCTexture2D* textrue=new CCTexture2D();
textrue->autorelease();
textrue->initWithImage(_image);
_sprite=CCSprite::createWithTexture(textrue);
_initPoint=ccp(clippingNode->getContentSize().width/2, clippingNode->getContentSize().height/2);
_sprite->setPosition(_initPoint);
CCSize spriteSize=_sprite->getContentSize();
if (size.width/spriteSize.width<size.height/spriteSize.height) {
_scale=size.width/spriteSize.width;
}else{
_scale=size.height/spriteSize.height;
}
_sprite->setScale(_scale);
clippingNode->addChild(_sprite);
//创建裁剪模板,裁剪节点将按照这个模板来裁剪区域
CCDrawNode *stencil = CCDrawNode::create();
CCPoint rectangle[4];
rectangle[0] = ccp(0, 0);
rectangle[1] = ccp(clippingNode->getContentSize().width, 0);
rectangle[2] = ccp(clippingNode->getContentSize().width, clippingNode->getContentSize().height);
rectangle[3] = ccp(0, clippingNode->getContentSize().height);
ccColor4F white = {1, 1, 1, 1};
//画一个多边形 这画一个200x200的矩形作为模板
stencil->drawPolygon(rectangle, 4, white, 1, white);
clippingNode->setStencil(stencil);
//用来设置显示裁剪区域还是非裁剪区域的
clippingNode->setInverted(false);//在裁剪区域内显示加入的内容
_clip=CCClippingNode::create();//创建裁剪节点,成员变量
_clip->setInverted(true);//设置底板可见
_clip->setAlphaThreshold(0.0f);//设置alpha为0
m_contentLayer->addChild(_clip);//添加裁剪节点
_mask=CCLayerColor::create(ccc4(0,0,0,160),size.width,size.height);
CCPoint point=ccp(middle.x-size.width/2,middle.y-size.height/2);
_mask->setPosition(point);
_clip->addChild(_mask);//为裁剪节点添加一个黑色带透明(看起了是灰色)的底板
_stencil=CCSprite::create("default_avatar.png");//使用头像原图作为模板
_stencil->setPosition(middle);
_stencil->setScale(STENCIL_SCALE);
_clip->setStencil(_stencil);//设置模版
CCSprite* queding=CCSprite::createWithSpriteFrameName("touxiang_queding.png");
CCMenuItemSprite* item=CCMenuItemSprite::create(queding, queding, this, menu_selector(ImageEditLayer::menuCallback));
item->setPosition(ccp(290,-30));//注意contentlayer坐标原点位置
item->setScale(0.7);
item->setTag(kTagConfirm);
this->addMenuItem(item,true);
CCSprite* fanhui=CCSprite::createWithSpriteFrameName("touxiang_fanhui.png");
fanhui->setScale(0.87);
CCMenuItemSprite* fanhuiItem=CCMenuItemSprite::create(fanhui, fanhui, this, menu_selector(ImageEditLayer::menuCallback));
fanhuiItem->setPosition(ccp(19,368));
fanhuiItem->setTag(kTagBack);
this->addMenuItem(fanhuiItem,true);
CCPoint contentPoint=m_contentLayer->getPosition();
_rect=CCRectMake(contentPoint.x+point.x, contentPoint.y+point.y, size.width,size.height);
return true;
}
return false;
}
示例11: CCRectMake
bool Recipe26::init()
{
if ( !RecipeBase::init() )
{
return false;
}
CCLayerColor* panelBg = CCLayerColor::create(ccc4(51, 51, 51, 255),640,1150);
panelBg->setPosition(ccp(0,0));
this->addChild(panelBg);
targetLayer = CCLayer::create();
this->addChild(targetLayer);
// 画面の幅を取得
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
// 画像ファイルとrectを指定してスプライトを作成
CCSprite *player = CCSprite::create("image/quest/shuriken_m_avatar_skillpg_18.png", CCRectMake(0, 0, 100, 100) );
// スプライトの位置を設定
player->setPosition(ccp(player->getContentSize().width*3/2, winSize.height/2));
// 後で識別できるようにタグを設定
player->setTag(1);
// スプライトをレイヤに追加
targetLayer->addChild(player);
CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
TapSprite* sprite = (TapSprite*)TapSprite::create("image/quest/shuriken_m_avatar_skillpg_18.png");
sprite->setPosition(ccp(visibleSize.width/2, visibleSize.height/2));
sprite->setTag(2);
targetLayer->addChild(sprite);
// クリック用のボタン
CCMenuItemImage *pCloseItem = CCMenuItemImage::create(
"image/ui/common_ui_mainButton_up.png",
"image/ui/common_ui_mainButton_down.png",
this,
menu_selector(Recipe26::testBtn1Handler));
// 表示位置を指定
pCloseItem->setPosition(ccp(winSize.width - pCloseItem->getContentSize().width / 2 ,
pCloseItem->getContentSize().height / 2));
// CCMenuItemImage から CCMenuを作成
CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
// CCMenuとしての位置は(0,0)を指定
pMenu->setPosition(-150,130);
this->addChild(pMenu);
//---------------------------
CCSize size = CCDirector::sharedDirector()->getVisibleSize();
CCSprite* pSprite = CCSprite::create("image/gacha/2204401.jpg");
pSprite->setPosition( ccp(size.width/2, size.height/2) );
CCSprite* pMask = CCSprite::create("image/quest/mask_star.png");
pMask->setPosition(ccp(size.width/2, size.height/2));
CCClippingNode* pClip = CCClippingNode::create();
pClip->setStencil(pMask);
pClip->setAlphaThreshold(0.05f);
pClip->addChild(pSprite);
targetLayer->addChild(pClip);
CCMoveTo *actionMove = CCMoveTo::create(1.7f, ccp(200, 500));
pClip->runAction(CCEaseExponentialInOut::create(actionMove));
//---------------------------
// 配列のテスト
//---------------------------
int arrN[] = {5,6,9,4};
int iSize = sizeof(arrN) / sizeof(arrN[0]);
for ( int i = 0 ; i < iSize ; i++ ) {
CCLOG("ffgff : %i" , arrN[i]);
}
return true;
}