Exemplo n.º 1
0
ClippingNode* SpriteInvertedTest::clipper()
{
    auto clipper = SpriteTest::clipper();
    clipper->setAlphaThreshold(0.05f);
    clipper->setInverted(true);
    return clipper;
}
Exemplo n.º 2
0
void PlayStage::countAnimeBoom(Point position)
{
	auto mask = ClippingNode::create();
	mask->setStencil(LayerColor::create(Color4B(0, 0, 0, 255), _screenSize.width, 240.0f));
	mask->setAlphaThreshold(255);
	mask->setInverted(false);

    auto count_boom_anime = ParticleSystemQuad::create("count_boom_ver2.plist");
	count_boom_anime->setAutoRemoveOnFinish(true);
	count_boom_anime->setPosition(position);
	count_boom_anime->setLifeVar(0.2f);
    
    auto chainLabel = Label::createWithBMFont("ui_font.fnt", std::to_string(chains) + " Chains!!");
    chainLabel->setScale(0);
    chainLabel->runAction(Sequence::create(EaseBackIn::create(ScaleTo::create(0.4f, 2.0f)),
                                           EaseBackOut::create(ScaleTo::create(0.18f, 1.0f)),
                                           DelayTime::create(0.4f),
                                           FadeOut::create(0.3f),
										   CallFunc::create(CC_CALLBACK_0(Label::removeFromParentAndCleanup, chainLabel, true)),
										   NULL));
    chainLabel->setPosition(position);
    
    //anime_sprite->addChild(count_anime);
    
	mask->addChild(count_boom_anime);
	mask->addChild(chainLabel);
	ballSheetMask->addChild(mask, 500);
}
Exemplo n.º 3
0
MaskPolygon &MaskPolygon::operator=(const MaskPolygon otherPoly)
{
    if (this == &otherPoly)
        return *this;
    setMaskType(otherPoly.getMaskType());
    setMaskPolygon(otherPoly.getMaskPolygon());
    setImgNr(otherPoly.getImgNr());
    setInverted(otherPoly.isInverted());
    return *this;
};
Exemplo n.º 4
0
void ClippingToRenderTextureTest::reproduceBug()
{
    auto director = Director::getInstance();
    Size visibleSize = director->getVisibleSize();
    Point origin = director->getVisibleOrigin();


    // add "HelloWorld" splash screen"
    auto sprite = Sprite::create("Images/grossini.png");

    // position the sprite on the center of the screen
    sprite->setPosition(Point(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));

    // add the sprite as a child to this layer
    this->addChild(sprite, 0);


    // container node that will contain the clippingNode
    auto container = Node::create();
    container->retain();

    auto stencil = DrawNode::create();
    Point triangle[3];
    triangle[0] = Point(-50, -50);
    triangle[1] = Point(50, -50);
    triangle[2] = Point(0, 50);
    Color4F green(0, 1, 0, 1);
    stencil->drawPolygon(triangle, 3, green, 0, green);

    auto clipper = ClippingNode::create();
    clipper->setAnchorPoint(Point(0.5, 0.5));
    clipper->setPosition( Point(visibleSize.width/2, visibleSize.height/2) );
    clipper->setStencil(stencil);
    clipper->setInverted(true);
    container->addChild(clipper, 1);


    auto img = DrawNode::create();
    triangle[0] = Point(-200, -200);
    triangle[1] = Point(200, -200);
    triangle[2] = Point(0, 200);
    Color4F red(1, 0, 0, 1);
    img->drawPolygon(triangle, 3, red, 0, red);
    clipper->addChild(img);

    // container rendered on Texture the size of the screen and because Clipping node use stencil buffer so we need to
    // create RenderTexture with depthStencil format parameter
    RenderTexture* rt = RenderTexture::create(visibleSize.width, visibleSize.height, Texture2D::PixelFormat::RGBA8888, GL_DEPTH24_STENCIL8);
    rt->setPosition(visibleSize.width/2, visibleSize.height/2);
    this->addChild(rt);

    rt->begin();
    container->visit();
    rt->end();
}
void SelectionController::createSelection(const sf::IntRect& rect, const sf::Image& image, const std::vector<nSet::o_line>& conf_l) {
	createSelection(rect, &image);
	setInverted(false);

	pos_lines = new nSet::positionned_olines();
	pos_lines->lines = std::vector<nSet::o_line>(conf_l);
	pos_lines->pos = getPosition();
	updateCadre();

	UNDO->push(*new SelecUpdated(this, *image_selec, pos_lines->pos, *pos_lines, inverted));
	emit selectionCreated();
}
Exemplo n.º 6
0
void ClippingToRenderTextureTest::expectedBehaviour()
{
    auto director = Director::getInstance();
    Size visibleSize = director->getVisibleSize();
    Point origin = director->getVisibleOrigin();


    // add "HelloWorld" splash screen"
    auto sprite = Sprite::create("Images/grossini.png");

    // position the sprite on the center of the screen
    sprite->setPosition(Point(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));

    // add the sprite as a child to this layer
    this->addChild(sprite, 0);
    sprite->setName("remove me 0");

    // container node that will contain the clippingNode
    auto container = Node::create();
    this->addChild(container);
    container->setName("remove me 1");

    auto stencil = DrawNode::create();
    Point triangle[3];
    triangle[0] = Point(-50, -50);
    triangle[1] = Point(50, -50);
    triangle[2] = Point(0, 50);
    Color4F green(0, 1, 0, 1);
    stencil->drawPolygon(triangle, 3, green, 0, green);

    auto clipper = ClippingNode::create();
    clipper->setAnchorPoint(Point(0.5, 0.5));
    clipper->setPosition( Point(visibleSize.width/2, visibleSize.height/2) );
    clipper->setStencil(stencil);
    clipper->setInverted(true);
    container->addChild(clipper, 1);


    auto img = DrawNode::create();
    triangle[0] = Point(-200, -200);
    triangle[1] = Point(200, -200);
    triangle[2] = Point(0, 200);
    Color4F red(1, 0, 0, 1);
    img->drawPolygon(triangle, 3, red, 0, red);
    clipper->addChild(img);
}
Exemplo n.º 7
0
void PlayStage::countAnime(Point position)
{
    
    //auto anime_sprite = Sprite::create();
	auto mask = ClippingNode::create();
	mask->setStencil(LayerColor::create(Color4B(0, 0, 0, 255), _screenSize.width, 240.0f));
	mask->setAlphaThreshold(255);
	mask->setInverted(false);
    
    auto count_anime = ParticleSystemQuad::create("Count_anime.plist");
    count_anime->setAutoRemoveOnFinish(true);
    count_anime->setPosition(position);
    
    //anime_sprite->addChild(count_anime);
    
	mask->addChild(count_anime);
	ballSheetMask->addChild(mask, 500);
}
///////////////
// INTERSECT //
///////////////
void SelectionController::intersectSelection(const sf::IntRect& rect, const std::vector<nSet::o_line>& conf_l) {
	if (isSelected()) {
		intersectSelection(rect, static_cast<sf::Image*>(NULL));
		setInverted(false);

		pos_lines = new nSet::positionned_olines(*pos_lines);
		FOR_I_INV (pos_lines->lines.size())
			if (!rect.contains(pos_lines->lines[i].x, pos_lines->lines[i].y))
				pos_lines->lines.erase(pos_lines->lines.begin() + i);
		pos_lines->lines.insert(pos_lines->lines.end(), conf_l.begin(), conf_l.end());
		pos_lines->pos = getPosition();
	
		if (!reline()) {
			UNDO->push(*new SelecUpdated(this, *image_selec, pos_lines->pos, *pos_lines, inverted));
			emit selectionUpdated(3);
		}
	}
	else
Exemplo n.º 9
0
void HoleDemo::setup()
{
    auto target = Sprite::create(s_pathBlock);
    target->setAnchorPoint(Vec2::ZERO);
    target->setScale(3);
    
    _outerClipper = ClippingNode::create();
    _outerClipper->retain();
    AffineTransform tranform = AffineTransform::IDENTITY;
    tranform = AffineTransformScale(tranform, target->getScale(), target->getScale());

    _outerClipper->setContentSize( SizeApplyAffineTransform(target->getContentSize(), tranform));
    _outerClipper->setAnchorPoint( Vec2(0.5, 0.5) );
    _outerClipper->setPosition(Vec2(this->getContentSize()) * 0.5f);
    _outerClipper->runAction(RepeatForever::create(RotateBy::create(1, 45)));
    
    _outerClipper->setStencil( target );
    
    auto holesClipper = ClippingNode::create();
    holesClipper->setInverted(true);
    holesClipper->setAlphaThreshold( 0.05f );
    
    holesClipper->addChild(target);
    
    _holes = Node::create();
    _holes->retain();
    
    holesClipper->addChild(_holes);
    
    _holesStencil = Node::create();
    _holesStencil->retain();
    
    holesClipper->setStencil( _holesStencil);
    
    _outerClipper->addChild(holesClipper);
    
    this->addChild(_outerClipper);
    
    auto listener = EventListenerTouchAllAtOnce::create();
    listener->onTouchesBegan = CC_CALLBACK_2(HoleDemo::onTouchesBegan, this);
    _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
}
Exemplo n.º 10
0
ClippingNode* HelloWorld::_makeClippingNode(Point* mask, int count, Point* physicBody, int p_count, Sprite* content)
{
	auto sprite = _duplicateSprite(content);	//复制精灵
	
	
	auto _clipper = ClippingNode::create();
	_clipper->setPosition(content->getPosition());
	_clipper->setInverted(true);// //显示切割后剩余部分
	_clipper->setOpacity(0);	//设置透明度
	_clipper->setAnchorPoint(Point::ZERO); //设置定位点,显示图层  参考http://www.cnblogs.com/pengyingh/articles/2433081.html
	_clipper->addChild(sprite);
	auto shape = _makeDrawNode(mask, count);	//这里画形状
	_clipper->addChild(shape);	//然后将这形状模板加到遮罩类子类里,这步可能只是用来保存遮罩形状,以免以后用到吧
	_clipper->setStencil(shape);//创建裁剪模板  参考 http://www.gulumiao.com/blog/2013/11/%E5%85%B3%E4%BA%8Ecocos2dx%E9%81%AE%E7%BD%A9ccclippingnode/
	
	//_clipper->setPhysicsBody(PhysicsBody::createPolygon(physicBody, p_count,
	//													PHYSICSBODY_MATERIAL_DEFAULT));
	sprite->setPosition(Point::ZERO);

	return _clipper;
}
Exemplo n.º 11
0
ClippingNode* ShapeInvertedTest::clipper()
{
    auto clipper = ShapeTest::clipper();
    clipper->setInverted(true);
    return clipper;
}
Exemplo n.º 12
0
bool TeachLayer::init(const cocos2d::Vec2 &stencilWorldPos, FingerDirection fingerDirection)
{
    if (!Layer::init())
    {
        return false;
    }
    
    _stencilPosition = stencilWorldPos;
    _fingerDirection = fingerDirection;
    
    Size winSize = Director::getInstance()->getWinSize();
    
    // bind touch event
    auto touchListener = EventListenerTouchOneByOne::create();
    touchListener->setSwallowTouches(true);
    // bind touch event
    touchListener->onTouchBegan = CC_CALLBACK_2(TeachLayer::onTouchBegan, this);
    touchListener->onTouchEnded = CC_CALLBACK_2(TeachLayer::onTouchEnded, this);
    _eventDispatcher->addEventListenerWithSceneGraphPriority(touchListener, this);
    
    // 裁剪图层
    auto pClip = ClippingNode::create();
    // 设置反相
    pClip->setInverted(true);
    
    // 蒙版
    auto colorLayer = LayerColor::create(Color4B(0, 0, 0, 180));
    pClip->addChild(colorLayer);
    
    // 模板初始化
    _stencilNode = DrawNode::create();
    // 绘制圆形区域
    float fRadius = 55.0f; // 圆的半径
    const int nCount = 100; // 圆形其实可以看做正多边形,我们这里用正100边型来模拟园
    const float coef = 2.0f * (float)M_PI / nCount; // 计算每两个相邻顶点与中心的夹角
    Vec2 circle[nCount]; // 顶点数组
    for(int i = 0;i < nCount; i++)
    {
        float rads = i*coef;//弧度
        circle[i].x = fRadius * cosf(rads); // 对应顶点的x
        circle[i].y = fRadius * sinf(rads); // 对应顶点的y
    }
    // 绘制这个多边形!
    _stencilNode->drawPolygon(circle, nCount, Color4F::GREEN, 0, Color4F::GREEN);
    
    _stencilNode->setPosition(winSize.width * 0.5, winSize.height * 0.5);
    // 设模板
    pClip->setStencil(_stencilNode);
    addChild(pClip);
    
    _stencilButton = SpriteButton::create("guide_circle.png", CC_CALLBACK_1(TeachLayer::stencilTouchCallBack, this));
    _stencilButton->setOpacity(0);
    _stencilButton->setPosition(winSize.width * 0.5, winSize.height * 0.5);
    addChild(_stencilButton);
    
    _fingerSprite = Sprite::createWithSpriteFrameName("finger_1.png");
    addChild(_fingerSprite);
    
    _fingerEffSprite = Sprite::createWithSpriteFrameName("finger_2.png");
    addChild(_fingerEffSprite);
    
    setStencilPosition(_stencilPosition);
    
    runMoveAction();
    
    return true;
}
Exemplo n.º 13
0
int QRangeModel::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QObject::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: valueChanged((*reinterpret_cast< qreal(*)>(_a[1]))); break;
        case 1: positionChanged((*reinterpret_cast< qreal(*)>(_a[1]))); break;
        case 2: stepSizeChanged((*reinterpret_cast< qreal(*)>(_a[1]))); break;
        case 3: invertedChanged((*reinterpret_cast< bool(*)>(_a[1]))); break;
        case 4: minimumChanged((*reinterpret_cast< qreal(*)>(_a[1]))); break;
        case 5: maximumChanged((*reinterpret_cast< qreal(*)>(_a[1]))); break;
        case 6: positionAtMinimumChanged((*reinterpret_cast< qreal(*)>(_a[1]))); break;
        case 7: positionAtMaximumChanged((*reinterpret_cast< qreal(*)>(_a[1]))); break;
        case 8: toMinimum(); break;
        case 9: toMaximum(); break;
        case 10: setValue((*reinterpret_cast< qreal(*)>(_a[1]))); break;
        case 11: setPosition((*reinterpret_cast< qreal(*)>(_a[1]))); break;
        case 12: { qreal _r = valueForPosition((*reinterpret_cast< qreal(*)>(_a[1])));
            if (_a[0]) *reinterpret_cast< qreal*>(_a[0]) = _r; }  break;
        case 13: { qreal _r = positionForValue((*reinterpret_cast< qreal(*)>(_a[1])));
            if (_a[0]) *reinterpret_cast< qreal*>(_a[0]) = _r; }  break;
        default: ;
        }
        _id -= 14;
    }
#ifndef QT_NO_PROPERTIES
      else if (_c == QMetaObject::ReadProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: *reinterpret_cast< qreal*>(_v) = value(); break;
        case 1: *reinterpret_cast< qreal*>(_v) = minimum(); break;
        case 2: *reinterpret_cast< qreal*>(_v) = maximum(); break;
        case 3: *reinterpret_cast< qreal*>(_v) = stepSize(); break;
        case 4: *reinterpret_cast< qreal*>(_v) = position(); break;
        case 5: *reinterpret_cast< qreal*>(_v) = positionAtMinimum(); break;
        case 6: *reinterpret_cast< qreal*>(_v) = positionAtMaximum(); break;
        case 7: *reinterpret_cast< bool*>(_v) = inverted(); break;
        }
        _id -= 8;
    } else if (_c == QMetaObject::WriteProperty) {
        void *_v = _a[0];
        switch (_id) {
        case 0: setValue(*reinterpret_cast< qreal*>(_v)); break;
        case 1: setMinimum(*reinterpret_cast< qreal*>(_v)); break;
        case 2: setMaximum(*reinterpret_cast< qreal*>(_v)); break;
        case 3: setStepSize(*reinterpret_cast< qreal*>(_v)); break;
        case 4: setPosition(*reinterpret_cast< qreal*>(_v)); break;
        case 5: setPositionAtMinimum(*reinterpret_cast< qreal*>(_v)); break;
        case 6: setPositionAtMaximum(*reinterpret_cast< qreal*>(_v)); break;
        case 7: setInverted(*reinterpret_cast< bool*>(_v)); break;
        }
        _id -= 8;
    } else if (_c == QMetaObject::ResetProperty) {
        _id -= 8;
    } else if (_c == QMetaObject::QueryPropertyDesignable) {
        _id -= 8;
    } else if (_c == QMetaObject::QueryPropertyScriptable) {
        _id -= 8;
    } else if (_c == QMetaObject::QueryPropertyStored) {
        _id -= 8;
    } else if (_c == QMetaObject::QueryPropertyEditable) {
        _id -= 8;
    } else if (_c == QMetaObject::QueryPropertyUser) {
        _id -= 8;
    }
#endif // QT_NO_PROPERTIES
    return _id;
}