Rakoonic

Quick hacked 'group origin' concept

Sep 4th, 2013
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.29 KB | None | 0 0
  1.  
  2. -- The overall group (this could represent the scene.view in storyboard)
  3. local sceneGroup = display.newGroup()
  4.  
  5. -- Your group, where everything resides
  6. local gameGroup = display.newGroup()
  7. sceneGroup:insert( gameGroup )
  8.  
  9. -- Create some items within it
  10. for i = 1, 10 do
  11.     local rect = display.newRect( gameGroup, math.random( 0, 430 ), math.random( 0, 270 ), 50, 50 )
  12. end
  13.  
  14. -- My first quick attempt at the 'change origin of groups'
  15. local function setGroupOrigin( group, x, y )
  16.  
  17.     -- Store parent
  18.     local parentGroup = group.parent
  19.    
  20.     -- Create in-between group and offset
  21.     local topGroup    = display.newGroup()
  22.     local bottomGroup = display.newGroup() 
  23.     group.parent:insert( topGroup )
  24.     topGroup:insert( bottomGroup )
  25.     bottomGroup:insert( group )
  26.  
  27.     topGroup.x    = x
  28.     topGroup.y    = y
  29.     bottomGroup.x = -x
  30.     bottomGroup.y = -y
  31.        
  32.     -- Return the new group
  33.     return topGroup, bottomGroup
  34.    
  35. end
  36.  
  37. -- Change the origin of the group to the middle of the
  38. --gameGroup = setGroupOrigin( gameGroup, 240, 160 )
  39.  
  40. -- Now set it rotating
  41. local function enterFrame( event )
  42.  
  43.     gameGroup.rotation = gameGroup.rotation + 5
  44.     gameGroup.xScale   = 1 + math.random( -10, 10 ) / 100
  45.     gameGroup.yScale   = 1 + math.random( -10, 10 ) / 100
  46.    
  47. end
  48. Runtime:addEventListener( "enterFrame", enterFrame )
Add Comment
Please, Sign In to add comment