Shapes "inside" shape

Hi :slight_smile: i’m testing the corona sdk and i love…:slight_smile:
but now i have an question…
I want to create a shape “inside” another shape…
i have the code to create a few boxes.
i have one group called boxes then i create the box like this:
local box = display.newRect( boxes, 0, 0, boxSize, boxSize)
and now i want to create 2 circles in this box and that circle has to move with the box…(i have implemented the code for drag’n drop…

Any help? [import]uid: 77944 topic_id: 17460 reply_id: 317460[/import]

your shape in a shape can be created if you place all these shapes in a group. If you have used any vector illustration apps, think GROUPS

cheers,

?:slight_smile: [import]uid: 3826 topic_id: 17460 reply_id: 66251[/import]

I cannot tell you as I cannot see how you are moving the box…

However, here’s an example

[lua]local theGroup = display.newGroup()
local obj

obj = display.newRect(theGroup, 10,10,50,20)
obj = display.newRect(theGroup, 100,100,50,20)
obj = display.newRect(theGroup, 10,200,50,20)

–Now let us move this group

transition.to(theGroup,{time=1000, x=display.contentWidth, y=display.contentHeight})[/lua]

cheers,

?:slight_smile: [import]uid: 3826 topic_id: 17460 reply_id: 66264[/import]

Hi :slight_smile: thanks.
I will try… but i already have the box’s in one Group…called boxes.
how i move all the box’s in the boxes group?
I try but corona sdk stop working when i click in one of the box…

Thanks,
Cheers

EDIT: I found one solution here: http://developer.anscamobile.com/content/problem-moving-display-group

but i think this isn’t my case…
[import]uid: 77944 topic_id: 17460 reply_id: 66262[/import]

Hi, this is my code:

  
physics.addBody(ground, "static", {friction = 0.1})  
  
   
-- CREATE 'BOXES' DISPLAY GROUP & BOXES  
   
-- A display group we can loop through -  
-- works just like a table, but allows us to perform other display functions upon the boxes as well.  
-- Be sure to use boxes.numChildren instead of #boxes when getting the number of boxes in the group,  
-- but otherwise it works just like a table (which is really just an array)  
  
local boxes = display.newGroup()  
   
  
-- It adds that box to the 'boxes' display group  
  
local function addBox()  
  
 local box = display.newRect(0, 0, boxSize, boxSize)  
  
 box.x =boxSize  
 box.y =\_H/2  
 box.area = box.height \* box.width  
 box.density = 3.0  
 box.mass = box.area \* box.density  
  
 box:setFillColor( math.random(0,255), math.random(0,255), math.random(0,255) )  
 local olho=display.newCircle(box.x, box.y, 10 )  
  
 physics.addBody( box, { density=3.0, friction=0.5 } )  
  
end  
  
-- CREATE SET NUMBER OF BOXES (DEFINED IN SETTINGS ABOVE)  
  
 for i=1, numberOfBoxes do  
 -- addBox()  
 end  
   
-- TOUCH TO DRAG FUNCTION  
  
local function dragBody(e)  
 local body = e.target  
 local phase = e.phase  
 local stage = display.getCurrentStage()  
  
 if(phase == "began") then  
 stage:setFocus(body, e.id)  
 body.isFocus = true  
 body.tempJoint = physics.newJoint("touch", body, e.x, e.y)  
 elseif(phase == "moved") then  
 if(body.tempJoint ~= nil) then  
 body.tempJoint:setTarget(e.x, e.y)  
 end  
 elseif(phase == "ended" or phase == "cancelled") then  
 if(body.tempJoint ~= nil) then  
 stage:setFocus(body, nil)  
 body.isFocus = false  
 body.tempJoint:removeSelf()  
 body.tempJoint = nil  
 end  
 end  
   
 return true  
end  
   
 for i=1, boxes.numChildren do  
 boxes[i]:addEventListener("touch", dragBody)  
 end  

When i drag the box i want the shapre “olho” moves together with the box…

Cheers, [import]uid: 77944 topic_id: 17460 reply_id: 66266[/import]