2
I am solving a college exercise in Orona SDK in the realization of a small game, but I have a small problem in the hour when the ball will fall from "top" for the second time. The point is that I need to drop the balls from the top of the phone to be able to deviate with my object "character" which is however a blue square. The first time when the program is run, the ball can fall normally, and as soon as it touches the ground it erases and creates another new one on the top of the cell phone, but it does not apply gravity so it can fall, the Corona generates the following error:
Follow the drawing of the ball along with the applied gravity, and the call of the drawing method of the ball for it to be created again.
--Personagem
quad[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 checks and recreation of the object "ball":
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 anyone can give a boost! Thank you.