Scale a group?

I have not found many resources on the web pertaining to scaling a group.

I have multiple images housed inside a single group. I would like to scale the group so everything inside scales with it. Is this possible?

I have already tried the following -

object.xScale (and .yScale) - didnt work

object:scale (x, y) - didnt work

Once again, I am trying to scale the group so everything in it will scale as well.

Any help would be beneficial. Please advise. Thank you. :slight_smile:

@Joe,

I think you may have  a code problem elsewhere?  My guess is scope and visibliity.

Try the following code, or download it here.

https://www.youtube.com/watch?v=IIYX2KyFYvA&feature=youtu.be&hd=1

main.lua

local centerX = display.contentCenterX local centerY = display.contentCenterY local function makeGroupSet( x, y )     local group = display.newGroup()     local tmp = display.newCircle( group, 0, 0, 20 )         local tmp = display.newCircle( group, 40, 0, 20 )     tmp:setFillColor(1,0,0)     local tmp = display.newCircle( group, -40, 0, 20 )     tmp:setFillColor(1,1,0)     local tmp = display.newCircle( group, 0, 40, 20 )     tmp:setFillColor(1,0,1)     local tmp = display.newCircle( group, 0, -40, 20 )     tmp:setFillColor(0,1,1)     group.x = x     group.y = y     return group end local set1 = makeGroupSet( centerX - centerX/2 - 40, centerY ) local set2 = makeGroupSet( centerX, centerY ) local set3 = makeGroupSet( centerX + centerX/2 + 40, centerY ) -- xScale/yScale set1.xScale = 0.5 set1.yScale = 0.5 -- obj:scale() set2:scale( 0.5, 0.5 ) -- Transitions local upScale local downScale upScale = function ( set )     transition.to( set, { xScale = 1.5, yScale = 1.5, time = 500, onComplete=downScale }) end downScale = function( set )     transition.to( set, { xScale = 0.1, yScale = 0.1, time = 500, onComplete=upScale }) end downScale( set3 ) 

config.lua

application = {     content = {         width = 320,         height = 480,          scale = "letterbox",         fps = 30,     }, } 

build.settings

settings = {    orientation = {       --default = "portrait",       --supported = { "portrait", "portraitUpsideDown" },       default = "landscapeLeft",       supported = { "landscapeRight", "landscapeLeft" },    }, } 

It should work when you use the xScale and yScale on the group.

-- main.lua local i1 = display.newImage("image1.png"); i1.x = 0; local i2 = display.newImage("image2.png"); i2.x = -200; local i3 = display.newImage("image3.png"); i3.x = 200; local g = display.newGroup(); g:insert(i1); g:insert(i2); g:insert(i3); g.x = display.contentCenterX; g.xScale = 3; g.yScale = 3;

Those examples are great! Thanks for the help. I actually am convinced now that I typed something wrong…I don’t remember because I delete code if it doesn’t work…

Anyway, what I am saying is that I tried “groupName:scale ( x, y)” again, and it works now… :blink:

Why? I have no idea, like I said I think I just typed it wrong or perhaps put it in the wrong place when I typed it before, or something. But the code examples here have still been lots of help to me as far as understanding code. Thanks for the responses y’all. :D 

@Joe,

I think you may have  a code problem elsewhere?  My guess is scope and visibliity.

Try the following code, or download it here.

https://www.youtube.com/watch?v=IIYX2KyFYvA&feature=youtu.be&hd=1

main.lua

local centerX = display.contentCenterX local centerY = display.contentCenterY local function makeGroupSet( x, y )     local group = display.newGroup()     local tmp = display.newCircle( group, 0, 0, 20 )         local tmp = display.newCircle( group, 40, 0, 20 )     tmp:setFillColor(1,0,0)     local tmp = display.newCircle( group, -40, 0, 20 )     tmp:setFillColor(1,1,0)     local tmp = display.newCircle( group, 0, 40, 20 )     tmp:setFillColor(1,0,1)     local tmp = display.newCircle( group, 0, -40, 20 )     tmp:setFillColor(0,1,1)     group.x = x     group.y = y     return group end local set1 = makeGroupSet( centerX - centerX/2 - 40, centerY ) local set2 = makeGroupSet( centerX, centerY ) local set3 = makeGroupSet( centerX + centerX/2 + 40, centerY ) -- xScale/yScale set1.xScale = 0.5 set1.yScale = 0.5 -- obj:scale() set2:scale( 0.5, 0.5 ) -- Transitions local upScale local downScale upScale = function ( set )     transition.to( set, { xScale = 1.5, yScale = 1.5, time = 500, onComplete=downScale }) end downScale = function( set )     transition.to( set, { xScale = 0.1, yScale = 0.1, time = 500, onComplete=upScale }) end downScale( set3 ) 

config.lua

application = {     content = {         width = 320,         height = 480,          scale = "letterbox",         fps = 30,     }, } 

build.settings

settings = {    orientation = {       --default = "portrait",       --supported = { "portrait", "portraitUpsideDown" },       default = "landscapeLeft",       supported = { "landscapeRight", "landscapeLeft" },    }, } 

It should work when you use the xScale and yScale on the group.

-- main.lua local i1 = display.newImage("image1.png"); i1.x = 0; local i2 = display.newImage("image2.png"); i2.x = -200; local i3 = display.newImage("image3.png"); i3.x = 200; local g = display.newGroup(); g:insert(i1); g:insert(i2); g:insert(i3); g.x = display.contentCenterX; g.xScale = 3; g.yScale = 3;

Those examples are great! Thanks for the help. I actually am convinced now that I typed something wrong…I don’t remember because I delete code if it doesn’t work…

Anyway, what I am saying is that I tried “groupName:scale ( x, y)” again, and it works now… :blink:

Why? I have no idea, like I said I think I just typed it wrong or perhaps put it in the wrong place when I typed it before, or something. But the code examples here have still been lots of help to me as far as understanding code. Thanks for the responses y’all. :DÂ