I am using a shake event to subtract 1 from a global variable (bullseyeOne) every time the phone is shaken. It works fine unless I use my button to reload the page using director. After I reload, I subtract 2 every shake. reload again, and subtract 3, etc.
Obviously doing something wrong. Sure would appreciate some pointers, I’m pretty new at this. Thanks!
[lua]module(…, package.seeall)
function new()
local localGroup = display.newGroup()
display.setStatusBar(display.HiddenStatusBar)
local background = display.newImage (“farmbg.jpg”)
localGroup:insert(background)
local function pressBack(event) – director function reloads page
if event.phase == “ended” then
director:changeScene (“level1”, "fade ")
end
end
– display button to relaod page
local backButton = display.newImage (“againButton.png”)
backButton.x = 160
backButton.y = 455
localGroup:insert(backButton)
backButton:addEventListener( “touch”, pressBack)
local function shakeme( event ) – shake event subtracts 1 from bullseyeOne
if (event.isShake) then
myCircle = display.newCircle( 90, 140, 50 )
myCircle:setFillColor(0,0,0)
myCircle:setStrokeColor ( 255, 0, 0)
myCircle.strokeWidth = 2
transition.to (myCircle, {time=3000, alpha =0})
_G.bullseyeOne = _G.bullseyeOne - 1
print("bullseyeOne = "…bullseyeOne)
end
end
Runtime:addEventListener(“accelerometer”,shakeme)
return localGroup
end
[/lua] [import]uid: 96383 topic_id: 17522 reply_id: 317522[/import]