@marco231 wrote:
Hi Guys,
I'm making this game that takes an image and mask it over puzzle pieces . I've achieved a decent amount using clipping node below is a screenshot.
The problem is when I clip the main image and mask it on the piece, it takes the same location of the image. I realise that when I call my method that it calls the same sprite (entire image) . But what I'm trying to do is slice my sprite into quadrants and then mask this image over a piece. Below is my code for my method
void Piece::createMaskWithPuzzle(std::string puzzle, std::string piece, Point offset, int i)
{
Size visibleSize = Director::getInstance()->getVisibleSize();
Vec2 origin = Director::getInstance()->getVisibleOrigin();//this is a sprite need to mask auto heroCard = Sprite::create(puzzle); heroCard->setAnchorPoint(Point(0,1)); //this is a mask sprite auto mask = Sprite::createWithSpriteFrameName(piece); heroCard->setPosition(Point(i * mask->getContentSize().width, mask->getContentSize().height)); mask->setPosition(heroCard->getPosition()); mask->setAnchorPoint(heroCard->getAnchorPoint()); //settings up the masks ClippingNode *holseClipper = ClippingNode::create(); holseClipper->setInverted(false); holseClipper->setAlphaThreshold(0); holseClipper->addChild(heroCard); Node *node = Node::create(); node->addChild(mask); holseClipper->setStencil(node); this->addChild(holseClipper); //set the mask position to the heroCard heroCard->setPosition(this->getPositionX(),this->getPositionY()+this->getContentSize().height); mask->setPosition(heroCard->getPosition());
}
Hope someone can shed some light on the situation.
Thanks
Marco
Posts: 1
Participants: 1