Hi , i was writing some samples for understand how to build things and i figured out i can’t afford some points at all
In my program ( for now ) i want 2 write 2 circles on the screen after x time .
When the circle spawn i want it to have 3 second cooldown , after it kill himself and disappear
If the circle is clicked between the start and 3 disappear too
now , i want to solve some problem that i will list now
- my code is really not optimized , i can’t create a table with my circle inside for expamle can you help me ?
- the event clickButton doesen’t start at all , and i can’t fix that … really
- i was wondering to do the “disappear time” of the circle with a timer.performWithDelay but it doesn’t work at all .
this is my code :
[lua]-----------------------------------------------------------------------------------------
– main.lua
local levelTime = 60
local startTime = os.time()
local b = {} — tables for Circle objects
local tmp = {} – tables for times
local First = 0 – like a bool variable
local Second = 0 – like a bool variable
function onClickCircle (event)
local t = event.target
b[t]:removeSelf()
b[t] = nil
end
function createCircle (x,y)
local xpos = x
local ypos = y
local radius = 50
local circle = display.newCircle( xpos, ypos, radius );
circle:setFillColor( 255, 255, 255, 255 );
circle.radius = radius
circle:addEventListener (“touch”, onClickCircle)
return circle
end
local function checkTime( event )
now = os.time()
local delta = now - startTime – for check the time
print(delta)
if (delta == 1) then
if(Second == 0) then
b[1] = createCircle(19,29)
tmp[1] = os.time() +3
Second = Second + 1
end
elseif (delta == 2) then
if(Second == 1)then
b[2] = createCircle (100,150)
tmp[2] = os.time() +3
Second = Second +1
end
end
if (First == 0) then
if (now == tmp[1]) then
b[1]:removeSelf()
First = First +1
end
elseif (First == 1) then
if (now == tmp[2]) then
b[2]:removeSelf()
First = First +1
end
end
end
Runtime:addEventListener( “enterFrame”, checkTime )
[/lua]