本文整理汇总了C++中CCClippingNode::setAnchorPoint方法的典型用法代码示例。如果您正苦于以下问题:C++ CCClippingNode::setAnchorPoint方法的具体用法?C++ CCClippingNode::setAnchorPoint怎么用?C++ CCClippingNode::setAnchorPoint使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCClippingNode
的用法示例。
在下文中一共展示了CCClippingNode::setAnchorPoint方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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);
}
示例2: init
bool CSignLayer::init()
{
if (BaseLayer::init())
{
MaskLayer* lay = MaskLayer::create("CSignLayermask");
lay->setContentSize(CCSizeMake(2824,640));
LayerManager::instance()->push(lay);
m_ui = LoadComponent("Sign.xaml"); // SelectSkill
m_ui->setPosition(VCENTER);
this->addChild(m_ui);
this->setOpacity(180);
//背景框
CImageView* pImageRect = (CImageView*)m_ui->findWidgetById("board_sign");
//添加一个裁切层
CCClippingNode* pClip = CCClippingNode::create();
CImageView* pImage = UICloneMgr::cloneImageView(pImageRect);
pImage->setAnchorPoint(ccp(0.5f, 0.5f));
pImage->setPosition(ccp(pImage->getContentSize().width/2, pImage->getContentSize().height/2));
pClip->setStencil(pImage);
pClip->setContentSize(pImageRect->getContentSize());
pClip->setAnchorPoint(pImageRect->getAnchorPoint());
pClip->setPosition(pImageRect->getPosition());
pImageRect->getParent()->addChild(pClip, pImageRect->getZOrder()+1);
m_pClip = pClip;
//展示区图片
m_show_info_scroll = (CScrollView*)m_ui->findWidgetById("scroll_info");
m_show_info_scroll->setDirection(eScrollViewDirectionVertical);
m_show_info_scroll->setBounceable(true);
m_pInfo1 = (CLabel*)m_ui->findWidgetById("info_1");
CC_SAFE_RETAIN(m_pInfo1);
m_pInfo1->removeFromParentAndCleanup(false);
m_show_info_scroll->getContainer()->addChild(m_pInfo1);
m_pInfo1->setAnchorPoint(ccp(0, 1));
CC_SAFE_RELEASE(m_pInfo1);
m_pInfo2 = (CLabel*)m_ui->findWidgetById("info_2");
CC_SAFE_RETAIN(m_pInfo2);
m_pInfo2->removeFromParentAndCleanup(false);
m_show_info_scroll->getContainer()->addChild(m_pInfo2);
m_pInfo2->setAnchorPoint(ccp(0, 1));
CC_SAFE_RELEASE(m_pInfo2);
updateShowInfoScroll();
m_show_info_scroll->setVisible(false);
CCNode* pMaskInfo = (CCNode*)m_ui->findWidgetById("mask_info");
pMaskInfo->setVisible(false);
m_pLineEffect = new CLineLightEffect;
m_pLineEffect->bindUI(m_ui);
m_pLineEffect->bindRectEffect(pImageRect);
this->addChild(m_pLineEffect, 999);
m_pYellowTip = CCSprite::create("sign/lightbox5.png");
m_pYellowTip->setAnchorPoint(ccp(0.5f, 0.0f));
m_pYellowTip->setScale(0.8f);
m_pYellowTip->runAction(CCRepeatForever::create(CCSequence::createWithTwoActions(CCMoveBy::create(0.3f, ccp(0, -10)), CCMoveBy::create(0.3f, ccp(0, 10)))));
m_ui->addChild(m_pYellowTip, 50);
m_pYellowTipText = UICloneMgr::cloneLable((CLabel*)m_ui->findWidgetById("day1"));
m_pYellowTipText->setAnchorPoint(ccp(0.5f, 0.5f));
m_pYellowTipText->setPosition(ccp(m_pYellowTip->getContentSize().width/2, m_pYellowTip->getContentSize().height/2+12));
m_pYellowTipText->setScale(1.2f);
m_pYellowTip->addChild(m_pYellowTipText);
m_pYellowTip->setVisible(false);
return true;
}
return false;
}
示例3: 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);
}
}
示例4: 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);
}
}
示例5: 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;
}