Hi all, I’m working on an course taught by J.A. Whye I’ve gone over everything a few times, but I can’t see where I made my mistake. For some reason after I tap the “Tap here to start. Protect the planet!” 2 space ships appear, it’s only suppose to be 1 ship, I have no idea what happen.
Appreciate any help,
Project: Attack of the Cuteness Game -- housekeeping stuff --- display.setStatusBar(display.HiddenStatusBar) local centerX = display.contentCenterX local centerY = display.contentCenterY -- set up forward references --- local spawnEnemy local gameTitle -- preload audio --- local sndKill = audio.loadSound( "boing-1.wav" ) local sndBlast = audio.loadSound( "blast.mp3" ) local sndLose = audio.loadSound( "wahwahwah.mp3" ) -- create play screen --- local function createPlayScreen() local background = display.newImage("background.png") background.y = 130 background.alpha = 0 local planet = display.newImage("planet.png") planet.x = centerX planet.y = display.contentHeight + 260 planet.alpha = 0 transition.to( background, { time=3000, alpha=1, y=centerY, x=centerX} ) local function showTitle() gameTitle = display.newImage("gametitle.png") gameTitle.x = 120 gameTitle.y = 73 gameTitle.alpha = 0 gameTitle:scale(4, 4) transition.to( gameTitle, { time=500, alpha=1, xScale=1, yScale=1 }) startGame() end transition.to( planet, { time=4000, alpha=1, y=centerY, onComplete=showTitle } ) end --add onComplete -- -- game functions --- function spawnEnemy() local enemy = display.newImage("beetleship.png") enemy.x = math.random(20, display.contentWidth-20) enemy.y = math.random(20, display.contentHeight-20) enemy:addEventListener( "tap", shipSmash ) end function startGame() local text = display.newText( "Tap here to start. Protect the planet!", 0, 0, "Helvetica", 24 ) text.x = centerX text.y = display.contentHeight-30 text:setFillColor(0, 0, 255) local function goAway(event) display.remove(event.target) text = nil display.remove(gameTitle) spawnEnemy() end text:addEventListener( "tap", goAway ) end function planetDamage() end function hitPlanet(obj) end function shipSmash(event) local obj = event.target display.remove(obj) audio.play(sndBlast) end createPlayScreen() startGame()
Thank you