Skip to content

Instantly share code, notes, and snippets.

@SibGent
Created December 10, 2018 07:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SibGent/274823100b2397e0c5e468ff85e40fba to your computer and use it in GitHub Desktop.
Save SibGent/274823100b2397e0c5e468ff85e40fba to your computer and use it in GitHub Desktop.
Corona SDK – scale object on touch event
function scaleObject(event, scale)
assert(event, "event is missing")
local object = event.target
local scale = scale or 0.95
if event.phase == "began" then
object.xScale = scale
object.yScale = scale
object.isFocus = true
display.getCurrentStage():setFocus(object)
end
if event.phase == "moved" then
if event.x > object.contentBounds.xMax - 1
or event.x < object.contentBounds.xMin + 1
or event.y < object.contentBounds.yMin + 1
or event.y > object.contentBounds.yMax - 1 then
object.xScale = 1
object.yScale = 1
object.isFocus = false
else
if not object.isFocus then
object.xScale = scale
object.yScale = scale
object.isFocus = true
end
end
end
if event.phase == "ended" then
object.xScale = 1
object.yScale = 1
display.getCurrentStage():setFocus(nil)
end
if not object.isFocus then
event.phase = nil
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment