Help! What's an easy way to make a Pinch Zoom module?

Hello,

I want to create a module that allows me to pinch zoom other objects outside the module.

I found this tutorial, but when multi touches cross each other, the behavior becomes very weird.

Sometimes the display object disappears completely. :blink:

And I can’t restore default size in that tutorial.

I tried to google but there are nothing much about Pinch Zoom in Corona.

How do I create a module that allows me to pinch zoom (and restore) objects outside the module?

Thanks bunches!

edit: furthermore, I really want to make it runnable in simulator/debug

Any suggestion will be appreciated.

Hi @hydralisk_mk2,

This pinch-zoom-rotate module is the best I’ve seen, and it (should) work just fine in the Simulator too. I’m not sure how easily it can be “modulized” though… you might need to rework it somehow to make it cross-module compatible.

Brent

hi @hydralisk_mk2,

i have created a pinch-zoom-rotate module which can be (re)used.

mine is different from the other implementation because it works by enhancing (fixing) the native Corona touch events instead of adding display objects to represent touches.

it works in the simulator as well, but you’ll need something like Ultimote to pass in the multi-touch events. (Ultimote is inexpensive, even so, it’s worth every penny when doing multitouch development).

i have some documentation as well as examples which you’ll find in the code on my github repo.

http://docs.davidmccuskey.com/display/docs/dmc_multitouch.lua
https://github.com/dmccuskey/DMC-Corona-Library

cheers,
dmc

Thanks for reply.

I thought pinch zoom is a pretty common function.

But surprisingly there is no build-in API, isn’t it a bit inconvenient?

And… Is there any easy way to re-scale to default size? or I do have to store every applied scale factors?

Thanks.

re: re-scale

just apply xScale / yScale = 1. that should return the object to its default size.

re: pinch zoom commonality

pinch and zoom is a behavior we all know, but i think in reality it’s not used in very many applications so it’s not necessarily a common need. (i checked my iphone apps) :slight_smile:

i’ve also looked at many game engines (Lua and Python based) and have yet to see one which has pinch/zoom functionality part of its API; so apparently not a common need in the world of gaming apps either.

i will add that, from working on my touch libraries, i learned that advanced / complex touch scenarios basically require custom solutions to make sure that touches are handled correctly. it’s hard to abstract more than the basics to a re-useable module.

cheers,
dmc

Thanks.

About scale to default size, I was misled by this topic:

Not sure how it works in Cocos2d-X though.

I agree with you that games do not use pinch zoom often. But other apps that require this function are much more common though. Still looking forward to your updates. :lol:

Hi @dmc,

I just want to apologize real quick, I didn’t mean to “ignore” your module and promote the other one… I just honestly wasn’t aware of yours. I will definitely preview yours and add it to my list of bookmarks to recommend (along with Matt Webster’s) to anybody looking for a multitouch module.

Sincerely,

Brent Sorrentino

Hi Brent,

no need to apologize! the thought didn’t even cross my mind that you were promoting one library over the other. i already assumed that you didn’t know about my library because i don’t think most do; though there are those who have located and started using it, i haven’t officially “released” it as i have other modules to put out which probably have more mass appeal, like dmc_autostore. :slight_smile:

even though, i’d appreciate any exposure from you “pimping” my module. :slight_smile: let me know if you have any suggestions after you take a look.

cheers,
dmc

ps, though unnecessary as i have stated, it was thoughtful of you to clarify the situation. thanks!

pps, i emailed Inna last week after she and i talked about doing some guest tutorials. let me know if you have any suggestions. i’ll be sending some of my own to both of you soon.

cheers,
dmc

hi @hydralisk_mk2,

thanks for pointing out the link re: scaling. i just did a test with some code and it appears that scaling is not relative as that link suggests.

-- first test -- this keeps scale at 0.5, doesn't go to 0.25 ufo.xScale, ufo.yScale=0.5, 0.5 ufo.xScale, ufo.yScale=0.5, 0.5 -- second test -- this keeps my scale at 1.0 ufo.xScale, ufo.yScale=0.5, 0.5 ufo.xScale, ufo.yScale=0.5, 0.5 ufo.xScale, ufo.yScale=1.0, 1.0 ufo.xScale, ufo.yScale=40.0, 40.0 ufo.xScale, ufo.yScale=1.0, 1.0

cheers,
dmc

Hi @hydralisk_mk2,

This pinch-zoom-rotate module is the best I’ve seen, and it (should) work just fine in the Simulator too. I’m not sure how easily it can be “modulized” though… you might need to rework it somehow to make it cross-module compatible.

Brent

hi @hydralisk_mk2,

i have created a pinch-zoom-rotate module which can be (re)used.

mine is different from the other implementation because it works by enhancing (fixing) the native Corona touch events instead of adding display objects to represent touches.

it works in the simulator as well, but you’ll need something like Ultimote to pass in the multi-touch events. (Ultimote is inexpensive, even so, it’s worth every penny when doing multitouch development).

i have some documentation as well as examples which you’ll find in the code on my github repo.

http://docs.davidmccuskey.com/display/docs/dmc_multitouch.lua
https://github.com/dmccuskey/DMC-Corona-Library

cheers,
dmc

Thanks for reply.

I thought pinch zoom is a pretty common function.

But surprisingly there is no build-in API, isn’t it a bit inconvenient?

And… Is there any easy way to re-scale to default size? or I do have to store every applied scale factors?

Thanks.

re: re-scale

just apply xScale / yScale = 1. that should return the object to its default size.

re: pinch zoom commonality

pinch and zoom is a behavior we all know, but i think in reality it’s not used in very many applications so it’s not necessarily a common need. (i checked my iphone apps) :slight_smile:

i’ve also looked at many game engines (Lua and Python based) and have yet to see one which has pinch/zoom functionality part of its API; so apparently not a common need in the world of gaming apps either.

i will add that, from working on my touch libraries, i learned that advanced / complex touch scenarios basically require custom solutions to make sure that touches are handled correctly. it’s hard to abstract more than the basics to a re-useable module.

cheers,
dmc

Thanks.

About scale to default size, I was misled by this topic:

Not sure how it works in Cocos2d-X though.

I agree with you that games do not use pinch zoom often. But other apps that require this function are much more common though. Still looking forward to your updates. :lol:

Hi @dmc,

I just want to apologize real quick, I didn’t mean to “ignore” your module and promote the other one… I just honestly wasn’t aware of yours. I will definitely preview yours and add it to my list of bookmarks to recommend (along with Matt Webster’s) to anybody looking for a multitouch module.

Sincerely,

Brent Sorrentino

Hi Brent,

no need to apologize! the thought didn’t even cross my mind that you were promoting one library over the other. i already assumed that you didn’t know about my library because i don’t think most do; though there are those who have located and started using it, i haven’t officially “released” it as i have other modules to put out which probably have more mass appeal, like dmc_autostore. :slight_smile:

even though, i’d appreciate any exposure from you “pimping” my module. :slight_smile: let me know if you have any suggestions after you take a look.

cheers,
dmc

ps, though unnecessary as i have stated, it was thoughtful of you to clarify the situation. thanks!

pps, i emailed Inna last week after she and i talked about doing some guest tutorials. let me know if you have any suggestions. i’ll be sending some of my own to both of you soon.

cheers,
dmc

hi @hydralisk_mk2,

thanks for pointing out the link re: scaling. i just did a test with some code and it appears that scaling is not relative as that link suggests.

-- first test -- this keeps scale at 0.5, doesn't go to 0.25 ufo.xScale, ufo.yScale=0.5, 0.5 ufo.xScale, ufo.yScale=0.5, 0.5 -- second test -- this keeps my scale at 1.0 ufo.xScale, ufo.yScale=0.5, 0.5 ufo.xScale, ufo.yScale=0.5, 0.5 ufo.xScale, ufo.yScale=1.0, 1.0 ufo.xScale, ufo.yScale=40.0, 40.0 ufo.xScale, ufo.yScale=1.0, 1.0

cheers,
dmc

Hi @dmccuskey how can I make your library work with a group containing multiple images? I have two images side by side and I want to make them scalable but when I pass the group object the touches dont register? 

thanks

hi @saad,

do you have touch handlers on your images as well ?

can you send me your code so i can take a better look at what you’re trying to accomplish ? 

thanks

dmc

@dmc 

Im using dgoldman’s bookclass. the full code is over here: https://github.com/dgoldman/2-page-open-book/blob/master/BookClass.lua

I’m implementing your multitouch code here:

[lua]local function bookLoop()

local screenExit = false

– Initialize the book - display pages 1 and 2

leftPage = display.newImageRect(book.page[1].image, book.page[1].width, book.page[1].height)
bookGroup:insert (leftPage)
leftPage.x, leftPage.y = -book.pageWidth/2, 0 – Set with respect to containing group
leftPage.isVisible = true
leftPage.pageID = “Left”

rightPage = display.newImageRect(book.page[2].image, book.page[2].width, book.page[2].height)
bookGroup:insert (rightPage)
rightPage.x, rightPage.y = book.pageWidth/2, 0 – Set with respect to containing group
rightPage.isVisible = true
rightPage.pageID = “Right”
params = {
minScale = 1,
maxScale = 3

}
MultiTouch.activate( leftPage, “scale”, ‘multi’, params )[/lua]

Instead of leftpage I want to put bookGroup

Thanks!