Help with Collision of spawned object(postion fixed) with objects that there are translating on screen

Posted by Amrutha on Game Development See other posts from Game Development or by Amrutha
Published on 2011-04-24T08:12:48Z Indexed on 2011/06/23 16:32 UTC
Read the original article Hit count: 304

Filed under:
|
|
|

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.

© Game Development or respective owner

Related posts about iphone

Related posts about collision-detection