Keeping Image On Screen

Hi all,

I have implemented pinch to zoom and it works great. I have also set the min and max scale for the group and I and able to keep the images from leaving the left side of the screen but I can not figure out how to keep the image on the right side of the screen.

Here is my code.

if group.x \< 0 and group.xScale == 1 then group.x = 0 end if group.y \< 0 and group.yScale == 1 then group.y = 0 end

I can keep it from going off the screen on the top and left but I can figure out the code to keep it from going off the bottom and right.

Can anyone help?

Anyone?

if group.x >= display.contentWidth and group.xScale == 1 then
group.x = display.contentWidth
end

if group.y >=display.contentHeight and group.yScale == 1 then

group.y = display.contentHeight
end

why don’t you just add 2 more conditions?

Something like:

if group.x \> [put screenwidth here] and group.xScale == 1 then &nbsp; group.x = [your screenwidth] end &nbsp;

Hi eriklen,

That much I know about. The trouble I’m having is when the object is scaled up via pinch-to-zoom. I’m not sure how to keep it on the screen when the scale is greater than 1. Any ideas?

Thanks

Blondiemc9,

All display objects have width values and contentWidth values. contentWidth values are affected by scaling so it’s like you get the calculations for free.

if group.x+group.contentWidth*0.5>screen display width then

Anyone?

if group.x >= display.contentWidth and group.xScale == 1 then
group.x = display.contentWidth
end

if group.y >=display.contentHeight and group.yScale == 1 then

group.y = display.contentHeight
end

why don’t you just add 2 more conditions?

Something like:

if group.x \> [put screenwidth here] and group.xScale == 1 then &nbsp; group.x = [your screenwidth] end &nbsp;

Hi eriklen,

That much I know about. The trouble I’m having is when the object is scaled up via pinch-to-zoom. I’m not sure how to keep it on the screen when the scale is greater than 1. Any ideas?

Thanks

Blondiemc9,

All display objects have width values and contentWidth values. contentWidth values are affected by scaling so it’s like you get the calculations for free.

if group.x+group.contentWidth*0.5>screen display width then