Tile maps with Clipping nodes

Tile maps with Clipping nodes

Hello wanted to ask about Clipping nodes
Will clipping nodes work with tile maps? I’ve seen the clipping node example and notice that it only worked on sprites.

if I parented the tilemap to the clipping node and then the clipping node to the scene, would it work the same way?

Interesting. I haven’t tried this, but we can try and see what happens! The beauty of coding, we can try whatever we wish.

I tried this in my project, it rendered out a black screen and wasn’t really working that well.

This was how I initialized my clipper node

Size winSize = Director::getInstance()->getWinSize();
	clipper = ClippingNode::create();

	auto stencil = DrawNode::create();		

	Point triangle[3];		
	triangle[1] = Point(winSize.width * 1.5f, -winSize.height / 2);
	triangle[2] = Point(0, winSize.height);
	Color4F green(0, 1, 0, 1);

	stencil->drawPolygon(triangle, 3, green, 0, green);		

	clipper->setAnchorPoint(Vec2(0.5, 0.5)); 
	clipper->setPosition(winSize.width / 2, winSize.height / 2);

And when I created my tile map, instead of parenting the Tilemap to my scene, i parented it to my clipper node.

The result was just a full black screen.

To add on, my clipper node was in a separate singleton class with the scene node passed in through a function for no particular reason. I tried both, creating it within the scene and outside and both had the same result.

I can work with this my tomorrow

ClippingNode has a content size of (0, 0), so changing the anchor point does nothing. When you move it to the center of the screen, you are moving the visible part of your tile map off screen. If you comment out clipper->setInverted(true); then you should be able to see the bottom-left of your tile map.

What I get when I use:

//clipper->setPosition(winSize.width / 2.f, winSize.height / 2.f);
1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.