how to create a bag of coins

i want to create a bag of coins. Example mario bros; when you touch a coin, the coins text increase on 1 and disappears, help please!! :smiley: [import]uid: 138440 topic_id: 27302 reply_id: 327302[/import]

For the touching part look at collision detection (if you struggle check out Corona For Newbies Part 4) and for updating the score see here; http://corona.techority.com/2012/01/30/a-simple-score-system/

Peach :slight_smile: [import]uid: 52491 topic_id: 27302 reply_id: 110976[/import]

Hi, sorry for take too long to respond :smiley: i already create something like you propose.
but the issue i have is that i need to create an object for each coin because when i try to duplicate the same, the function do not work so how i can use like a “for” to create a lot of coins that works separately?

[lua]–adding the counter for the blood
local bloodcoin = 0

local blood = display.newText(“Blodd:”, 400, 10, “native.systemFont”, 35)
localGroup:insert(blood)
local bloddText = display.newText(bloodcoin, 500, 10, “native.systemFont”, 35)
localGroup:insert(bloddText)
–adding the blood image
local bloodImage = display.newCircle(300, 600, 10)
physics.addBody(bloodImage,“static”,{radius=10,density=0})
localGroup:insert(bloodImage)

local bloodImage2 = display.newCircle(370, 590, 10)
physics.addBody(bloodImage2,“static”,{radius=10})
localGroup:insert(bloodImage2)

bloodImage.preCollision = function(self)
bloodcoin = bloodcoin +1
bloddText.text= bloodcoin

self:removeSelf()

end
bloodImage2.preCollision = function(self)
bloodcoin = bloodcoin +1
bloddText.text= bloodcoin

self:removeSelf()

end

bloodImage:addEventListener(“preCollision”, bloodImage)
bloodImage2:addEventListener(“preCollision”, bloodImage2)
[import]uid: 138440 topic_id: 27302 reply_id: 111689[/import]

Plug and play code for portrait iPhone will show you how to spawn the coins in for loop and have all of them work for collision - will need modifying as isn’t based on your code but should show you how to get it all working smoothly;

[lua]require ( “physics” )
physics.start()
physics.setGravity( 0, 0 )

local player = display.newCircle( 160, 240, 40 )
player:setFillColor(255, 0, 0)
physics.addBody(player, “static”)

local coin = {}

for i = 1, 10 do
coin[i] = display.newCircle(math.random(1,320), math.random(1,480), 10)
physics.addBody(coin[i])
coin[i].myName = “coin”
end

local function playerCollision(event)
if event.other.myName == “coin” then
print “Collected coin”
event.other:removeSelf()
end
end
player:addEventListener(“collision”, playerCollision)

local function movePlayer(event)
player.x, player.y = event.x, event.y
end
player:addEventListener(“touch”, movePlayer)[/lua]

Peach :slight_smile: [import]uid: 52491 topic_id: 27302 reply_id: 111914[/import]