Hey guys I am creating a game using Corona SDK and so coding it in Lua. So there are 2 separate functions,

  1. To translate the hit objects and change their color when they are tapped The link below is the code I am using to for the first function http://developer.anscamobile.com/sample-code/fishies

  2. Spawn objects that will hit the translating objects on collision. Alos on collision the spawned object disappears and the translating object bears a color(indicating the collision). In addition the size of this spawned object is dependent on i/p volume level. The function I have written is as follows:

    local r = media.newRecording()
    --local function newBar()
    --    local bar = display.newLine( 0, 0, 1, 0 ) 
    --    bar:setColor( 0, 55, 100, 20 )
    --    bar.width = 5
    --    bar.y=400
    --    bar.x=20
    --    return bar
    local c1 = display.newImage("str-minion-small.png")
    local c2 = display.newImage("str-minion-mid.png")
    local c3 = display.newImage("str-minion-big.png")
    local function spawnDisk( event )
        local phase = event.phase
        local volumeBar = display.newLine( 0, 0, 1, 0 )
        volumeBar.y =  400
        volumeBar.x = 20
        local v = 20*math.log(r:getTunerVolume())    
        local MINTHRESH = 30
        local LEFTMARGIN = 20
        local v2 = MINTHRESH + math.max (v, -MINTHRESH)
        v2 = (display.contentWidth - 1 * LEFTMARGIN ) * v2 / MINTHRESH
        volumeBar.xScale =  math.max ( 20, v2 )
        local l = volumeBar.xScale
        local cnt1 = 0
        local cnt2 = 0
        local cnt3 = 0
        local ONE =1
        local val = event.numTaps
        --local px=event.x
        --local py=event.y
        if "ended" == phase then
            --audio.play( popSound )
            --myLabel.isVisible = false
            if l > 50 and l <=150 then
                c1.x=math.random( 10, 450 )
                c1.y=math.random( 10, 300 )
                physics.addBody( c1, { density=1, radius=10.0 } )
                cnt1= cnt1+ ONE
                return c1
            elseif l > 100 and l <=250 then
                c2.x=math.random( 10, 450 )
                c2.y=math.random( 10, 300 )
                physics.addBody( c2, { density=2, radius=9000.0 } )
                cnt2= cnt2+ ONE
                return c2
            elseif l >=250 then
                c3.x=math.random( 40, 450 )
                c3.y=math.random( 40, 300 )
                physics.addBody( c3, { density=2, radius=7000.0 , bounce=0.0 } )
                cnt3= cnt3+ ONE
                return c3
    buzzR:addEventListener( "touch", spawnDisk ) -- touch the screen to create disks

Now both functions work fine independently but there is no collision happening. Its almost as if the translating object and the spawn object are on different layers. The translating object passes through the spawn object freely.

Can anyone please tell me how to resolve this problem. And how can I get them to collide.

Its my first attempt at game development, that too for a mobile platform so would appreciate all help. Also if I have not been specific do let me know. I'll try to frame the query better :).

Thanks in advance.

  • 1
    \$\begingroup\$ I'd like to help because I am using Corona for my current project, but you need to fix the formatting of your code in order for it to be readable. Off the top of my head I would guess the issue is function scope from all the locals you are throwing around, but I can't tell where blocks of code begin and end because of the screwy formatting. \$\endgroup\$
    – jhocking
    Commented Apr 24, 2011 at 13:55
  • 1
    \$\begingroup\$ (hint hint you've posted other comments but still not fixed your code) \$\endgroup\$
    – jhocking
    Commented Apr 25, 2011 at 14:06

1 Answer 1


I think the problem is that the objects are all inserted into a group in the Fishies code. That is, your comment that they seem to be on different layers is correct. Note line 113:

group:insert( fishOriginal, true )

Physics don't work between display groups. This was done on purpose so that you can move the group around without affecting anything in the group, in order to do a moving camera like the Egg Breaker demo.

  • \$\begingroup\$ I guess that make sense. I didn't think of it at al. Thanks :).Ok but is there a way around this problem. Such that the object continue to translate and change color on tap but it all appears in the same layer (with the spawn object) \$\endgroup\$
    – Amrutha
    Commented Apr 24, 2011 at 17:58
  • \$\begingroup\$ Insert all objects into the same group. So instead of calling "local group = display.newGroup()" for every object, you do that just once at the top. Alternatively you could just not insert them in any group, but it is handy to be able to transition screens and such by manipulating an entire layer. \$\endgroup\$
    – jhocking
    Commented Apr 24, 2011 at 18:14
  • \$\begingroup\$ I inserted it on top but its working fine.Firtsly its displaying only one object that is translating at a very high speed(much faster than what an individual object was translating). Secondly I want to play sound files that would be unique to each bubble. This is the main need for the game. Kind of like a jigsaw but using voice as well. Finally I would like to say thanks for trying to help me, as I this is for my semester project(individual project) and so a novice like me could really use some good help :). \$\endgroup\$
    – Amrutha
    Commented Apr 25, 2011 at 12:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .