test test
test test

Reputation: 284

Hiding object with specific location

I'm new in Android games using corona and I use a timer to make a local display of coin with a 50x repetition. What I'm trying to do is if the character collide in on of coin the coin will disappaer, the problem is how can I hide that certain coin?

here's my code how I creating the coin.

function coins()
    coin1 = display.newImage( "coin1.png")
    coin1.x = math.random(0, 600)
    coin1.y = math.random(0, 400)
    coin1.myName = "wewe"
    physics.addBody(coin1, {friction = 1, density = 1})
end

timer.performWithDelay(
   1000, coins, 100 )

Upvotes: 1

Views: 62

Answers (1)

HennyH
HennyH

Reputation: 7944

have something like this

local function removeCoin(self,event)
   if(event.phase == "began") then
      self:removeSelf()
   end
end

And in coins() add the following

coin1.collision = removeCoin
coin1:addEventListener("collision",coin1)

This should make it that upon a coin experiencing a collision removeCoin is invoked, which removes it's caller, in this case a coin.

You can stop both objected being removed by doing something like this:

if(event.phase == "began" and self.myName == 'coin') then
      self:removeSelf()
end

Upvotes: 2

Related Questions