I am solving a college exercise in corona SDK in making a small game, however I have a small problem at the time the ball will fall from "top" for the second time. The point is that I need to drop the polka dots from the top of the phone so that I can deviate with my "character" object, which is however a blue square. The first time when the program is executed, the ball can fall normally, and as soon as it touches the ground it shuts off and a new one is created at the top of the cell, but it does not apply gravity so that it can fall, the crown generates the following error:
Followthedrawingoftheballalongwiththeappliedgravity,andcalltheballdrawingmethodforittobecreatedagain.
--Personagemquad[1]=display.newRect(200,400,50,50)quad[1]:setFillColor(0,0,255)quad[1].myName="personagem"
-- bola
local function desenhaBolinha()
local bola = {}
local raio = math.random(20,40)
local bolaX = math.random(0,320)
bola[1] = display.newCircle(bolaX,raio,raio)
bola[1]:setFillColor(255,0,0)
bola[1].anchorX = 0
bola[1].anchorY = 0
bola[1].y = 10
bola[1].myName = "bola"
phy.addBody(bola[1], "dynamic")
return (bola[1])
end
circ[1] = desenhaBolinha()
-- chão
quad[7] = display.newRect(0,500,700,10)
quad[7]:setFillColor(255,255,255)
quad[7].myName = "chao"
-- FISICA
local function grav()
phy.setGravity(0,20)
phy.addBody(circ[1], "dynamic")
phy.addBody(quad[7], "static")
phy.addBody(quad[1], "dynamic")
end
grav()
Method created below the code posted above, so that the collision and recreation checks of the "ball" object are done:
local function colisao(e)
--detecta colisao
if(e.phase == "began") then
print("began: " .. e.object1.myName .. " com " .. e.object2.myName)
elseif e.phase == "ended" then
print("ended: " .. e.object1.myName .. " com " .. e.object2.myName)
end
if(e.phase == "began" and e.object1.myName == "bola" and e.object2.myName == "personagem") then
text[2].text = text[10] - 1
end
if(e.phase == "began" and e.object1.myName == "bola" and e.object2.myName == "chao") then
circ[2] = e.object1
circ[2]:removeSelf()
circ[2] = desenhaBolinha()
end
end
If someone can give a force! Thanks.