Split one object in two by touch..

What would be my best approach if I want to split/divide one object
into two by using touch input to select where to split the object? 

Would the best approach be to record the touch input location, then
remove the object and render two new ones based on the input
coordinates?

To clearify, the effect I’m after would be to “cut of” a part of an object with the finger, such as: 

################

################

################

############

###########

#########

                       #

                     ##

                  ###

Many thanks for input on this! :slight_smile:

Games like Fruit ninja have the whole object and the two slices as three separate graphics.  The whole is shown, the two parts are hidden.  Then the touch happens, the whole is hidden/removed and the two parts are shown and then animated separating from each other.

We do not have facilities to arbitrarily slice an image into parts.

Thanks for the response!

Yes, fruit ninja would be a pretty good example of the effect I would like to create. The important part however would be to accurately “split” the image exactly where to touch happens (or to create two new object since it is not possible to split an object) … Is there any way to do this using corona?

Many thanks!

You cannot slice a single image into parts with Corona SDK. 

challenge accepted! :wink:

but yeah, I did some testing a while back with doing this. I started with trying to just divide a normal rectangle up into parts but since there isnt any good filling of a polygon I made a line version of it. It was abit rough and buggy but worked to a point:

http://www.youtube.com/watch?v=XfsUm_Wu_fA

then I though about using some of that technique and apply it to images using a divider mask:

http://www.youtube.com/watch?v=z7C2ZDMP47U

basically what I have is a mask that is half black and half white. Then I have one original image that you slice. I mark the starting point and ending point of the slice, then I calculate the angle that line has and the midpoint of that line. I then switch the original image with two other objects with their masks applied and rotated/moved so it corresponds to the slice. Havent really done much more testing with it so not sure how good it would work in an actual game. And it limits to dividing a object in half once. if you want to divide the bits again Im not sure how you would do it… maybe you would have to create new objects and apply the mask trick again, not sure if the display save thing saves transparent images yet…? 

It thought about masks, but the way I was thinking was complex and hackish.  This idea may work.

by request I made a github repository with the code as is:

https://github.com/Borgb/sliceit

mind you its not very neat or commented well since I was just testing and using some of the older code from the other test, so take it as it is. But maybe it will help some and maybe someone can make a better version of it :slight_smile:

Games like Fruit ninja have the whole object and the two slices as three separate graphics.  The whole is shown, the two parts are hidden.  Then the touch happens, the whole is hidden/removed and the two parts are shown and then animated separating from each other.

We do not have facilities to arbitrarily slice an image into parts.

Thanks for the response!

Yes, fruit ninja would be a pretty good example of the effect I would like to create. The important part however would be to accurately “split” the image exactly where to touch happens (or to create two new object since it is not possible to split an object) … Is there any way to do this using corona?

Many thanks!

You cannot slice a single image into parts with Corona SDK. 

challenge accepted! :wink:

but yeah, I did some testing a while back with doing this. I started with trying to just divide a normal rectangle up into parts but since there isnt any good filling of a polygon I made a line version of it. It was abit rough and buggy but worked to a point:

http://www.youtube.com/watch?v=XfsUm_Wu_fA

then I though about using some of that technique and apply it to images using a divider mask:

http://www.youtube.com/watch?v=z7C2ZDMP47U

basically what I have is a mask that is half black and half white. Then I have one original image that you slice. I mark the starting point and ending point of the slice, then I calculate the angle that line has and the midpoint of that line. I then switch the original image with two other objects with their masks applied and rotated/moved so it corresponds to the slice. Havent really done much more testing with it so not sure how good it would work in an actual game. And it limits to dividing a object in half once. if you want to divide the bits again Im not sure how you would do it… maybe you would have to create new objects and apply the mask trick again, not sure if the display save thing saves transparent images yet…? 

It thought about masks, but the way I was thinking was complex and hackish.  This idea may work.

by request I made a github repository with the code as is:

https://github.com/Borgb/sliceit

mind you its not very neat or commented well since I was just testing and using some of the older code from the other test, so take it as it is. But maybe it will help some and maybe someone can make a better version of it :slight_smile:

Great, but if i want to split 1 image into many small images, how do it, borgb???

Thank a lof!

if you want to do that in one slice I would just create all the small pieces in advance and let the image explode when you slice it. if you want to slice the sliced pieces again and again you would have to create new images from the sliced ones (save out transparent pngs with the alpha if that is possible) and use those images to create new objects that can be sliced again. Not sure how smooth this would work or if its possible now, havent tried it, maybe someone here has.

Thanks for your answer, have a nice day!

Great, but if i want to split 1 image into many small images, how do it, borgb???

Thank a lof!

if you want to do that in one slice I would just create all the small pieces in advance and let the image explode when you slice it. if you want to slice the sliced pieces again and again you would have to create new images from the sliced ones (save out transparent pngs with the alpha if that is possible) and use those images to create new objects that can be sliced again. Not sure how smooth this would work or if its possible now, havent tried it, maybe someone here has.

Thanks for your answer, have a nice day!