[Resolved] Zooming in and out and with transition

Hi everyone.

I was trying to zoom an ImageGroup in my game with transition.to but only got weird results so I set up this test project to demonstrate my problems, maybe anyone can tell me what I am doing wrong?

local group = display.newGroup()  
  
local rect1 = display.newRect(100, 100, 100, 100)  
  
group:insert(rect1)  
  
function shrink()   
 group.width = 50  
 group.height = 50  
end  
  
function inflate()  
 group.width = 200  
 group.height = 200  
end  
  
function transitionShrink()  
 transition.to(group, { time = 3000, width = 50, height = 50 } )  
end  
  
timer.performWithDelay(3000, shrink)  
timer.performWithDelay(6000, inflate)  
timer.performWithDelay(9000, transitionShrink)  

The shrink() and inflate() functions work now. transitionShrink() however, shrinks the group until it is no longer visible. Thus, I have 2 questions

  1. When I debug my program, the width/height will always be 100, no matter what I set this to. Is this normal?
  2. To to correctly apply the transition? [import]uid: 139365 topic_id: 30195 reply_id: 330195[/import]

If you want to zoom in/out, shouldn’t you be using xScale and yScale? [import]uid: 160496 topic_id: 30195 reply_id: 120921[/import]

+1 Mike.

Change the transition to:
[lua]transition.to(group, { time = 3000, xScale = 0.5, yScale=0.5 } )[/lua]

That should work perfectly. [import]uid: 52491 topic_id: 30195 reply_id: 120932[/import]

Yes it does, thanks!

Just out of curiosity though, when would one set width and height then? [import]uid: 139365 topic_id: 30195 reply_id: 120940[/import]

I don’t think that width and height can be used in a transition. Anybody want to confirm? I might be mistaken.

If that is so, but you really need a specific width/height, as in, you need to shrink an object or group to a specific size, you could use this workaround…

local w = object.width  
local h = object.height  
local wS = w / 300 --300 being new desired width  
local hS = h / 140 --140 being new desired height  
transition.to( object, { time = 3000, xScale = wS, yScale=hS } )  

I know that seems a bit troublesome, but it would accomplish the goal. Of course this would only work for shrinking something; you’d need to reverse the terms ( 300 / w , 140 / h ) if you wanted to upsize something to a specific size.

Brent

[import]uid: 9747 topic_id: 30195 reply_id: 120977[/import]

If you want to zoom in/out, shouldn’t you be using xScale and yScale? [import]uid: 160496 topic_id: 30195 reply_id: 120921[/import]

+1 Mike.

Change the transition to:
[lua]transition.to(group, { time = 3000, xScale = 0.5, yScale=0.5 } )[/lua]

That should work perfectly. [import]uid: 52491 topic_id: 30195 reply_id: 120932[/import]

Yes it does, thanks!

Just out of curiosity though, when would one set width and height then? [import]uid: 139365 topic_id: 30195 reply_id: 120940[/import]

I don’t think that width and height can be used in a transition. Anybody want to confirm? I might be mistaken.

If that is so, but you really need a specific width/height, as in, you need to shrink an object or group to a specific size, you could use this workaround…

local w = object.width  
local h = object.height  
local wS = w / 300 --300 being new desired width  
local hS = h / 140 --140 being new desired height  
transition.to( object, { time = 3000, xScale = wS, yScale=hS } )  

I know that seems a bit troublesome, but it would accomplish the goal. Of course this would only work for shrinking something; you’d need to reverse the terms ( 300 / w , 140 / h ) if you wanted to upsize something to a specific size.

Brent

[import]uid: 9747 topic_id: 30195 reply_id: 120977[/import]