Hey guys I have been working on a app for awhile but I am stuck on this problem. So when my player is touched it will change the score to plus one. But it only works once any ideas?
My code down below. :blink:
_local score = require(“score”)
local physics = require “physics”
physics.start()
local numberSmiles = 1 --local variable; amount can be changed
local bg = display.newRect(0,0,2000,2000);
–spawn parachute guy
local function spawnSmiles()
local score = 1
for i=1,numberSmiles do
local smile = display.newImage(“parachuteguy.png”)
– smile:setReferencePoint(display.CenterReferencePoint); --not necessary; center is default
smile.x = math.random(-10, 400);
smile.y = -40;
transition.to( smile, { time=math.random(2000,8000), x=math.random(-10,400) , y=600, onComplete=clearSmile } );
physics.addBody( smile, “dynamic”, { density=0.1, bounce=0.1, friction=0.1, radius=0 } );
smile:scale(0.5,0.5)
--destroy parachute guy on touch
local function onObjectTouch( event )
if event.phase == “began” then
print(“touch event began”)
smile:removeSelf()
score = score+1
print(score)
end
return true
end
smile:addEventListener(“touch”,onObjectTouch)
end
end_