Hi. I have this code:
[code]local physics = require(“physics”)
physics.start()
display.setStatusBar( display.HiddenStatusBar )
–physics.setDrawMode(“hybrid”)
local background = display.newImage(“background.jpeg”)
background.y = 210
local road = display.newImage(“road.jpg”,0,430)
local player = display.newImage(“player.png”)
player.x = display.contentWidth/2
player.y = 420
player.myName = “first crate”
local dreapta = display.newImage(“dreapta.png”)
dreapta.x = player.x +100
dreapta.y = 455
local stanga = display.newImage(“stanga.png”)
stanga.x = player.x - 100
stanga.y = 455
health = 164
local healthbar = display.newRect(143,9,health,16)
healthbar:setReferencePoint(display.TopLeftReferencePoint)
healthbar:setFillColor(38,130,224)
local health = display.newImage(“health.png”)
health:setReferencePoint(display.TopLeftReferencePoint)
health.x =135
health.y = 1
physics.addBody(road, {friction = 0.5})
road.bodyType = “static”
physics.addBody(player,{density=10.0,friction=0.2,bounce=0.3})
player.bodyType = “dynamic”
local function moveright (event)
player.x = player.x+5
end
local function moveleft (event)
player.x = player.x-5
end
local function wrapit(event)
if(player.x <32) then
player.x = 16
elseif player.x > 290 then
player.x = 305
end
end
local collisionBall = {}
–Function to spawn an object
function spawn()
local ball = display.newImage(“ball.png”)
ball.x = math.random(320)
ball.y = -100
physics.addBody(ball, {bounce = 0,density= 0.1, radius = 28})
transition.to(ball, {time=2000,y=600})
for j = 1 , #collisionBall do
collisionBall[j] = “second crate”
return ball
end
end
–Create a table to hold our spawns
local ballTable = {}
–Spawn two objects
local i = 1
local function spawnball ()
for i = 1,1 do
ballTable[i] = spawn()
end
for i = 1, #ballTable do
print(ballTable[i])
end
end
local function onLocalCollision(road,event)
if(event.phase == “ended”) then
print(“Collision”)
end
end
for j =1 ,#collisionBall do
collisionBall[j].myName = “second crate”
for j =1 ,#collisionBall do
collisionBall[j].collision = onLocalCollision
collisionBall[j]:addEventListener( “collision”, collisionBall[j] )
end
end
–Add Event Listeners
player.collision = onLocalCollision
player:addEventListener( “collision”, player )
Runtime:addEventListener(“enterFrame”, wrapit)
stanga:addEventListener(“touch”, moveleft)
dreapta:addEventListener(“touch”, moveright)
local spawner = timer.performWithDelay(500,spawnball,1000)[/code]
What should I edit to decrease the health rectangle everytime a collision is made? [import]uid: 178587 topic_id: 31491 reply_id: 331491[/import]