Saturday, August 19, 2017

ios - How do I break an image into 6 or 8 pieces of different shapes?


I am working on puzzle game, where the player can select an image from iPhone photo gallery. The selected image will save in puzzle page and after 3 second wait the selected image will be broken into 6 or 8 parts of different shapes. Then player will arrange these broken parts of images to make the original image.


I am not getting idea how to break the image and merged so that player arrange the broken part. I want to break image like this below frame. I am developing this game in cocos2d.


enter image description here



Answer



Since you have pre-made break patterns. All you really need to do is collect a sub-image for each one to show.


This would likely be easiest to do with a rectangle for each shape. The rectangle should encompass the entire shape. Now break the image up into these rectangles. There will be overlap. Now apply an alpha mask to each rectangle to hide everything but the shape it's encompassing.



For example some of the rectangles would look like this:


ops original image with rectangles around shapes


Then, for example, the texture for the black rectangle would be the portion of the image that is contained by the black rectangle. Then when that is masked out, only the shape portion of the image would remain.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...