Based off of whack a worm source code at mobile tuts. Looked at the code. Menu works with the sliding credits, but when I press play, all the hares show up.
Took a look at the popping function and the timer.
function startTimer()
timerSource = timer.performWithDelay(1400, showHare, 0)
end
function showHare(e)
if(currentHares == totalHares) then
alert()
else
lastHare.isVisible = false
local randomHole = math.floor(math.random() \* 8) + 1
lastHare = hares[randomHole]
lastHare:setReferencePoint(display.BottomCenterReferencePoint)
lastHare.yScale = 0.1
lastHare.isVisible = true
Runtime:addEventListener('enterFrame', popOut)
currentHares = currentHares + 1
end
end
function popOut(e)
lastHare.yScale = lastHare.yScale + 0.2
if(lastHare.yScale \>= 1) then
Runtime:removeEventListener('enterFrame', popOut)
end
end
function hareHit:tap(e)
audio.play(hit)
haresHit = haresHit + 1
score.text = haresHit .. '/' .. totalHares
lastHare.isVisible = false
end
This is what the main looks like with the movieclip added in to the source.
display.setStatusBar(display.HiddenStatusBar)
local movieclip = require('movieclip')
local bg = display.newImage('gameBg.png')
local titleBg
local playBtn
local creditsBtn
local titleView
local creditsView
local score
local h1
local h2
local h3
local h4
local h5
local h6
local h7
local h8
local hares
local lastHare = {}
local hit = audio.loadSound('hit.wav')
local timerSource
local currentHares = 0
local haresHit = 0
local totalHares = 10
local Main = {}
local startButtonListeners = {}
local showCredits = {}
local hideCredits = {}
local showGameView = {}
local prepareHares = {}
local startTimer = {}
local showHare = {}
local popOut = {}
local hareHit = {}
local alert = {}
function Main()
titleBg = display.newImage('titleBg.png')
playBtn = display.newImage('playBtn.png', display.contentCenterX - 25.5, display.contentCenterY + 40)
creditsBtn = display.newImage('creditsBtn.png', display.contentCenterX - 40.5, display.contentCenterY + 85)
titleView = display.newGroup(titleBg, playBtn, creditsBtn)
startButtonListeners('add')
end
function startButtonListeners(action)
if(action == 'add') then
playBtn:addEventListener('tap', showGameView)
creditsBtn:addEventListener('tap', showCredits)
else
playBtn:removeEventListener('tap', showGameView)
creditsBtn:removeEventListener('tap', showCredits)
end
end
function showCredits:tap(e)
playBtn.isVisible = false
creditsBtn.isVisible = false
creditsView = display.newImage('creditsView.png')
transition.from(creditsView, {time = 300, x = -creditsView.width, onComplete = function() creditsView:addEventListener('tap', hideCredits) creditsView.x = creditsView.x - 0.5 end})
end
function hideCredits:tap(e)
playBtn.isVisible = true
creditsBtn.isVisible = true
transition.to(creditsView, {time = 300, x = -creditsView.width, onComplete = function() creditsView:removeEventListener('tap', hideCredits) display.remove(creditsView) creditsView = nil end})
end
function showGameView:tap(e)
transition.to(titleView, {time = 300, x = -titleView.height, onComplete = function() startButtonListeners('rmv') display.remove(titleView) titleView = nil end})
score = display.newText('0' .. '/' .. totalHares, 58, 6, native.systemFontBold, 16)
score:setTextColor(238, 238, 238)
prepareHares()
end
function prepareHares()
h1 = display.newImage('hare.png', 80.5, 11)
h2 = display.newImage('hare.png', 198.5, 51)
h3 = display.newImage('hare.png', 338.5, 34)
h4 = display.newImage('hare.png', 70.5, 110)
h5 = display.newImage('hare.png', 225.5, 136)
h6 = display.newImage('hare.png', 376.5, 96)
h7 = display.newImage('hare.png', 142.5, 211)
h8 = display.newImage('hare.png', 356.5, 186)
hares = display.newGroup(h1, h2, h3, h4, h5, h6, h7, h8)
for i = 1, hare.numChildren do
hares[i]:addEventListener('tap', hareHit)
hares[i].isVisible = false
end
startTimer()
end
function startTimer()
timerSource = timer.performWithDelay(1400, showHare, 0)
end
function showHare(e)
if(currentHares == totalHares) then
alert()
else
lastHare.isVisible = false
local randomHole = math.floor(math.random() \* 8) + 1
lastHare = hares[randomHole]
lastHare:setReferencePoint(display.BottomCenterReferencePoint)
lastHare.yScale = 0.1
lastHare.isVisible = true
Runtime:addEventListener('enterFrame', popOut)
currentHares = currentHares + 1
end
end
function popOut(e)
lastHare.yScale = lastHare.yScale + 0.2
if(lastHare.yScale \>= 1) then
Runtime:removeEventListener('enterFrame', popOut)
end
end
function hareHit:tap(e)
audio.play(hit)
haresHit = haresHit + 1
score.text = haresHit .. '/' .. totalHares
lastHare.isVisible = false
end
function alert()
timer.cancel(timerSource)
lastHare.isVisible = false
local alert = display.newImage('alertBg.png')
alert:setReferencePoint(display.CenterReferencePoint)
alert.x = display.contentCenterX
alert.y = display.contentCenterY
transition.from(alert, {time = 300, xScale = 0.3, yScale = 0.3})
local score = display.newText(haresHit .. '/' .. totalHares, 220, 190, native.systemFontBold, 20)
score:setTextColor(204, 152, 102)
end
Main()
What am I doing wrong? Whats preventing the game from starting and why are all the objects shown?
[import]uid: 128294 topic_id: 22460 reply_id: 322460[/import]