bullet colliding with ship, help please!

Hi, Im getting along quite well with corona but Im stumped on collisions etc.

I have the following code to spawn bullets and enemy ships, they are in 2 separate functions and from looking at the collision help, it seems like objects you want to collide must be created in the same function. Im new to corona so I might be completely wrong. If anyone can help please do!

function fire()
local bullet = display.newCircle( ship.x, ship.y, 3 )
gamescreen:insert( 2, bullet )
laserchannel = audio.play( laser )
transition.to(bullet, { time = 500, x = centreX, y = centreY, width = 0.25, height = 0.25, onComplete = destroyHoop } )
end

function spawnobst(event)
if dospawnE == 1 then
Enemylane = mRand(1,2)
local ship = display.newImage(“shipafterburner.png”)
gamescreen:insert( 1 , ship )
ship.alpha = 0.2
ship.xScale = 0.01
ship.yScale = 0.01
ship.x = centreX
ship.y = centreY
I have skipped some bits of code as it would be a big post, but is there anyway of making a bullet in the first function collide with the ship in the second function?

Thanks [import]uid: 8699 topic_id: 5409 reply_id: 305409[/import]

It may just be that it’s Sunday, but since you haven’t gotten an answer in 8 hours, I’ll tell you why I didn’t answer: you didn’t provide a complete program I can test. I definitely don’t want something that’s 200 lines of code, though.

Sometimes to figure out a problem, I’ve found it to be a good exercise to try to boil the program down to the absolute minimal size that still illustrates the bug. Very often when you do this, you discover the answer on your own. And when you don’t, at least you have a minimal program people like me can use to try to help you.

Also, these forums let you post code using the <code> tag. It looks better and retains your indentation.

Best,
Mike
[import]uid: 9659 topic_id: 5409 reply_id: 18182[/import]

thanks for the tip. I don’t actually have a collision code at the moment though as I kept scrapping it. I think I can get it to work if I create the objects at the start of the program and recycle them, rather than creating a new instance whenever I fire etc. Although I’m sure it possible, I just don’t know how yet.

Thanks. [import]uid: 8699 topic_id: 5409 reply_id: 18184[/import]