Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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:

    --VOICE INPUT CODE
    local r = media.newRecording()
    r:startRecording()
    r:startTuner()
    
    --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
    --end
    
    local c1 = display.newImage("str-minion-small.png")
    c1.isVisible=false
    local c2 = display.newImage("str-minion-mid.png")
    c2.isVisible=false
    local c3 = display.newImage("str-minion-big.png")
    c3.isVisible=false
    
    --SPAWNING
    local function spawnDisk( event )
        local phase = event.phase
    
        local volumeBar = display.newLine( 0, 0, 1, 0 )
        volumeBar.y =  400
        volumeBar.x = 20
        --volumeBar.isVisible=false
    
        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:setFillColor(10,105,0)
                --c1.isVisible=false
                c1.x=math.random( 10, 450 )
                c1.y=math.random( 10, 300 )
                physics.addBody( c1, { density=1, radius=10.0 } )
                c1.isVisible=true
                cnt1= cnt1+ ONE
                return c1
    
            elseif l > 100 and l <=250 then
                --c2:setFillColor(200,10,0)
                c2.x=math.random( 10, 450 )
                c2.y=math.random( 10, 300 )
                physics.addBody( c2, { density=2, radius=9000.0 } )
                c2.isVisible=true
                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 } )
                c3.isVisible=true
                cnt3= cnt3+ ONE
                return c3
            end
        end
    end
    
    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.

share|improve this question
1  
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. –  jhocking Apr 24 '11 at 13:55
    
(hint hint you've posted other comments but still not fixed your code) –  jhocking Apr 25 '11 at 14:06
add comment

1 Answer

Although my comment about fixing the formatting of the code in your question still applies, 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.

share|improve this answer
    
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) –  Amrutha Apr 24 '11 at 17:58
    
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. –  jhocking Apr 24 '11 at 18:14
    
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 :). –  Amrutha Apr 25 '11 at 12:09
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.