在 Corona SDK 中实现缩放功能

我的应用程序中有缩放功能,我按照谷歌搜索的例子来实现了此功能。但是当我缩放图像时,图像走到了边界内部。在缩小时是完美的。但是当我在左或右角进行缩放时,图像没有与边界相匹配。请帮助我。

if "moved" == phase then
  if (tempGroup.distance) then
    local dx,dy
    if previousTouches and (numTotalTouches) >= 2 then
      dx,dy,midX,midY,offX,offY = calculateDelta(previousTouches, event)
    end

    if (dx and dy) then
      local newDistance = math.sqrt(dx*dx + dy*dy)
      modScale = newDistance / tempGroup.distance
      if (modScale > 0) then
        ----MODIFIED BY CON
        local newScale=tempGroup.xScaleOriginal * modScale
        -- uncomment below to set max and min scales
        maxScale, minScale = 3, 1
        if (newScale > maxScale) then
          newScale = maxScale
        end
        if (newScale < minScale) then
          newScale = minScale
        end

        tempGroup.xScale = newScale
        tempGroup.yScale = newScale
      end
    end
  end
end
点赞