Object scaling question

Hello, I have been trying to figure out a way to scale an object’s size during the duration of a touch touch event while also increasing a value associated with said object throughout the duration of the event.

ex. Player touches an object for 4 seconds which causes it’s size to steadily grow while also steadily increasing a variable during the 4 seconds.

Thanks in advance for the help. [import]uid: 66902 topic_id: 14020 reply_id: 314020[/import]

I played around a little, but cant figure out how to make proper timing, but its kinda works)
so if you manage it, please share your own method to solve this
[lua]local box = display.newRect(0,0,50,50)
box.x = 150
box.y = 150
box.xScale = 1
box.yScale = 1
Score = 0
boxtouched = false
Time = 0

function addtime()
Time = Time + 1
end

function touch_that(event)
if event.phase == “began” then
boxtouched = true
elseif event.phase == “ended” then
boxtouched = false
print(Time)
end
end

function sizebox()
if boxtouched == true then
box.xScale = box.xScale + 0.005
box.yScale = box.yScale + 0.005
timer.performWithDelay(1000, addtime,4)
elseif boxtouched == false then
return false
end
end

scoreField = display.newText(" ", 50,50, native.systemFont, 30)

function showScore()
if boxtouched == true then

end
end

box:addEventListener(“touch”, touch_that)
Runtime:addEventListener(“enterFrame”, sizebox)[/lua] [import]uid: 16142 topic_id: 14020 reply_id: 51654[/import]

Your best bet is to adjust the scale of your object using the object:scale() function.

I previously worked out a method for making an object scale up after the user dragged it past a certain line on the screen. For that I created a function called scaleUpToFullSize that was called once the object was dragged past a point. I also used an enterframe listener that did the actual scaling for me (transitions didn’t seem to be working well).

Hopefully you can use little parts of this. Especially the enterframe part, because that’s doing the actual scaling, just make sure you have some way of stopping it or it will just keep going.

Good Luck!
-Matt
W2MD

[lua] local scaleUpToFullsize = function(object)
local xScaleTemp, yScaleTemp = object.xScale, object.yScale
print("xScaleTemp, yScaleTemp: "…tostring( xScaleTemp), tostring( yScaleTemp))
–check for errors
if (xScaleTemp ~= yScaleTemp) then
print(“Error: “…tostring(object)…” is disproportionately scaled!”)
elseif (xScaleTemp == 1) then --object has not been scaled
return true
else --scale up to full size
print(“scaling up!”)
object.scalingUp = true
object.isFullSize = true --just for my own reference
end
end

– Scales objects after they move off of tray
function object:enterFrame( event )
if object.scalingUp == true then
object.xScale = object.xScale + object.xScale/10
object.yScale = object.yScale + object.yScale/10
if object.xScale >= 1.18 then
object.scalingUp = false
object.scalingDown = true
end
elseif object.scalingDown == true then
object.xScale = object.xScale - object.xScale/10
object.yScale = object.yScale - object.yScale/10
if object.xScale <= .9 then
object.xScale = 1
object.yScale = 1
object.scalingUp = false
object.scalingDown = false
end
elseif object.scalingUp == false and object.scalingDown ==false then
Runtime:removeEventListener(“enterFrame”, object)
object.enterFrame = nil
print(“eventlistener enterFrame removed from object”)
end
end
function object:touch( event )
local object, phase = event.target, event.phase
if “began” == phase then
object.isFocus = true
elseif object.isFocus then
if “moved” == phase then
if object.y <= display.contentHeight - TRAYHEIGHT and object.isFullSize == nil then
scaleUpToFullsize(object)

end
end
elseif “ended” == phase or “cancelled” == phase then
display.getCurrentStage():setFocus( nil )
object.isFocus = false
end
end

object:addEventListener( “touch”, object )
Runtime:addEventListener( “enterFrame”, object)[/lua] [import]uid: 10211 topic_id: 14020 reply_id: 51655[/import]

Thanks for the replies guys, should help me out very much. :slight_smile: [import]uid: 66902 topic_id: 14020 reply_id: 51657[/import]