Hello again,
Thanks Peach for helping out, but your never to slow…

Henrique,
Here’s some more simple code for ya to try, it’s one way
of doing things quick and easy to understand.
Depending on what your trying to do, or what end results
your after, it should help you along the way to your goal…
hopefully…
\_W = display.contentWidth;
\_H = display.contentHeight;
mRand = math.random;
total\_score = 0;
total\_score\_add = 5;
total\_rocks = 10;
-- text colors here
R = 255; -- a number from 0 - 255
G = 0;
B = 0;
local display\_score = display.newText(total\_score, 0, 0, native.systemFont, 32\*2)
display\_score:setReferencePoint(display.TopLeftReferencePoint);
display\_score.xScale = 0.5;
display\_score.yScale = 0.5;
display\_score.x = 25;
display\_score.y = 25;
display\_score:setTextColor(R, G, B)
local function changeRock(obj)
-- we are actually going to change the rock
-- NOT just change the color
-- dont' need this line if using images
local newRock = obj; -- copy obj (rock) to newRock before we remove the 1st one
-- use this line if using images
--local newRock= display.newImageRect("myBack.jpg",20,20);
-- you will have to set the x and y if your using
-- images...I left some homework for ya... ;)
obj:removeSelf(); -- remove 1st rock (obj) / image
-- use this line only if you are displaying images
newRock = display.newRect(newRock.x - 25, newRock.y - 25, 50, 50);
-- just to see remove the - 25 from x,y ABOVE and see if
-- this is a NEW rock
--don't need if using images
newRock:setFillColor(140, 0, 140)
return true;
end
local function addScore(event)
total\_score = (total\_score + total\_score\_add);
display\_score.text = total\_score;
return true;
end
local function trackRocks(obj)
--obj:removeSelf(); -- we will remove later in changeRock(obj) function
changeRock(obj);
addScore();
return true;
end
local function spawnRock()
--from Corona API docs
rock = display.newRect(0, 0, 50, 50)
rock:setReferencePoint(display.CenterReferencePoint);
rock.x = mRand(50,\_W-50);
rock.y = mRand(50,\_H-50);
rock.strokeWidth = 3;
rock:setFillColor(140, 140, 140);
rock:setStrokeColor(180, 180, 180);
function rock:touch(event)
if event.phase == "ended" then
trackRocks(self);
end
-- only remove one rock if it overlaps other rock(s)
return true;
end
rock:addEventListener("touch", rock);
end
tmr = timer.performWithDelay(40, spawnRock, total\_rocks);
…Happy Coding
Best Regards,
Larry [import]uid: 107633 topic_id: 21702 reply_id: 86301[/import]