Question

I have a problem and I saw it also in the game Candy Crush Saga, where they successfully dealt with it. I would like the sprite to show only when it is in the board (see image link below). The board can be of different shapes, like the levels in the mentioned game. Has anyone some ideas how can this be achieved with Cocos2d? I will be very glad if someone has some tips.

Thank you in advance.

image link: http://www.android-games.fr/public/Candy-Crush-Saga/candy-crush-saga-bonus.jpg

Was it helpful?

Solution 2

I found out Cocos2d has a class CCClippingNode which does exatclly what I wanted. First I thought it can clip only rectangular areas, but after some research I found it can clip also paths.

OTHER TIPS

In Cocos2d you can render sprites at different z levels. Images at a lower z-level will be drawn first by the graphic card and the images (sprites) with a higher z-value will be drawn later. Hence if an image (say A) is at the same position of the other but has a higher z-value you will see only the pixels of image A where the two images intersect.

Cocos2d uses also layers so you can decide to add Sprites to a layer and set the layer to a specific z value. I expect that they used a layer for the board (say at z=1) with a PNG image containing transparent bits in the area where you can see the sprites, and a second layer at z=0 for the sprites. In this way you can only see the sprites when they are in the transparent area.

Does this help?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top