Hey guys,
My game just became available in the App Store.
https://itunes.apple.com/app/heroes-vs.-mechs-tower-defense/id767652185
However, there’s a pretty major issue. When you go to another scene, the previous scene is not getting removed! This does not happen when I build it for my device. I have all my display objects inserted into self.view when I create the scene, so I doubt that is the problem.
Has anyone had a problem where the distribution version of the game builds differently from the developer version? I rebuilt the app and submitted it as an update via iTunes Connect, hoping that will magically solve the issue. However, since I can’t recreate the problem at all when I build it for my device, I didn’t make any changes to the code. I’m using version 2013.2076 (2013.07.15).
In case it is a code issue, here is the code for the main menu scene. Note that although I required the widget class, I did not use widgets (just used text), so I don’t think it’s problem of not removing the widgets when the scene is exited.
[lua]
–
– menu.lua
–
local storyboard = require( “storyboard” )
local scene = storyboard.newScene()
– include Corona’s “widget” library
local widget = require “widget”
local ads = require “ads”
local function onNewGameBtnRelease(self, event)
if event.phase == “ended” then
storyboard.gotoScene( “Menu Files.mapSelection”, “fade”, 300 )
end
end
local function onUpgradesBtnRelease(self, event)
if event.phase == “ended” then
storyboard.gotoScene( “Menu Files.upgrades”, “fade”, 300 )
end
end
– BEGINNING OF YOUR IMPLEMENTATION
–
– NOTE: Code outside of listener functions (below) will only be executed once,
– unless storyboard.removeScene() is called.
–
local emperor
– Called when the scene’s view does not exist:
function scene:createScene( event )
local group = self.view
local menuMusic = audio.loadStream(“Sounds/Future Gladiator.mp3”)
audio.play(menuMusic, {channel=1, loops=-1})
audio.setVolume(0.3, {channel=1})
local function adListener( event )
local msg = event.response
if event.isError then
– Failed to receive an ad, we print the error message returned from the library.
print(msg)
end
end
– ads.init( “iads”, “767652185”, adListener )
ads.init(“admob”, “a152964d667eaa6”, adlistener)
ads.show( “banner”, { x=0, y=0 } )
local sheetData = { width=32, height=32, numFrames=8 }
local sheet = graphics.newImageSheet( “Tower Defense Graphics/Heroes/Emperor.png”, sheetData )
local sequenceData = {
{ name=“up”, frames={1,2}, time=300},
{ name=“down”, frames={3,4}, time=300},
{ name=“left”, frames={5,6}, time=300},
{ name=“right”, frames={7,8}, time=300},
}
emperor = display.newSprite(sheet, sequenceData)
group:insert(emperor)
emperor:setSequence( “right” )
emperor:play()
emperor.direction = “right”
emperor.x, emperor.y = -20, 300
emperor.speech = display.newText("", 0, emperor.y - 70, 100, 100, “Minecraftia”, 8)
emperor.speech.isVisible = false
group:insert(emperor.speech)
emperor.touches = 0
function emperor:fade(teleportSprite)
teleportSprite:pause()
self.speech:removeSelf()
self:removeSelf()
transition.to(teleportSprite, {time = 1000, alpha=0, onComplete = function() teleportSprite:removeSelf() end})
end
function emperor:teleport()
local sheetData = { width=20, height=20, numFrames=10 }
local sheet = graphics.newImageSheet( “Tower Defense Graphics/Abilities/Teleport.png”, sheetData )
local sequenceData = {
{ name=“teleport”, start=1, count=10, time=625}
}
local teleportSprite = display.newSprite(sheet, sequenceData)
teleportSprite:scale(2, 2)
teleportSprite.x, teleportSprite.y = self.x, self.y
teleportSprite:play()
timer.performWithDelay(580, function() emperor:fade(teleportSprite) end)
end
function emperor:touch(event)
if event.phase == “began” then
self.touches = self.touches + 1
self.speech.isVisible = true
if self.touches == 1 then
self.speech.text = “Get yer hands off me! I AM THE EMPEROR!”
elseif self.touches == 2 then
self.speech.text = “If you really want to touch something, click the ad and support the developer.”
elseif self.touches == 3 then
self.speech.text = “Seriously, cut it out.”
elseif self.touches == 4 then
self.speech.text = “I’m warning you, one more time and you’re toast.”
elseif self.touches == 5 then
self.speech.text = “That’s it. I’m leaving. Have fun on map 10. *smirk*”
Runtime:removeEventListener(“enterFrame”, self)
self:pause()
timer.performWithDelay(2000, function() emperor:teleport() end)
end
end
end
emperor:addEventListener(“touch”, emperor)
function emperor:enterFrame(event)
if self.x == 20 then
self:setSequence(“right”)
self.direction = “right”
self:play()
self.x = 21
elseif self.x < display.contentWidth -20 and self.direction == “right” then
self.x = self.x + 1
elseif self.x == display.contentWidth - 20 then
self:setSequence(“left”)
self.direction = “left”
self:play()
self.x = display.contentWidth - 21
elseif self.x < display.contentWidth -20 and self.direction == “left” then
self.x = self.x - 1
end
if self.x > display.contentWidth/2 then
self.speech.x = self.x - 70
else
self.speech.x = self.x + 70
end
end
Runtime:addEventListener(“enterFrame”, emperor)
– create/position logo/title image on upper-half of the screen
local titleLogo = display.newText(“HEROES vs MECHS”, 0, 0, “Minecraftia”, 37)
titleLogo:setReferencePoint( display.CenterReferencePoint )
titleLogo.x = display.contentWidth * 0.5
titleLogo.y = 100
newGameBtn = display.newText(“New Game”, 0, 0, “Minecraftia”, 25)
newGameBtn:setReferencePoint( display.CenterReferencePoint )
newGameBtn.x = display.contentWidth * 0.5
– newGameBtn.y = 135
newGameBtn.y = 160
newGameBtn.touch = onNewGameBtnRelease
newGameBtn:addEventListener(“touch”, newGameBtn)
– resumeGameBtn = display.newText(“Resume”, 0, 0, “Minecraftia”, 25)
– resumeGameBtn:setReferencePoint( display.CenterReferencePoint )
– resumeGameBtn.x = display.contentWidth * 0.5
– resumeGameBtn.y = 190
– resumeGameBtn.touch = onResumeGameBtnRelease
– resumeGameBtn:addEventListener(“touch”, resumeGameBtn)
upgradesBtn = display.newText(“Upgrades”, 0, 0, “Minecraftia”, 25)
upgradesBtn:setReferencePoint( display.CenterReferencePoint )
upgradesBtn.x = display.contentWidth * 0.5
– upgradesBtn.y = 245
upgradesBtn.y = 205
upgradesBtn.touch = onUpgradesBtnRelease
upgradesBtn:addEventListener(“touch”, upgradesBtn)
– all display objects must be inserted into group
group:insert( titleLogo )
group:insert( newGameBtn )
– group:insert( resumeGameBtn )
group:insert( upgradesBtn )
end
– Called immediately after scene has moved onscreen:
function scene:enterScene( event )
local group = self.view
ads.show( “banner”, { x=0, y=0 } )
– INSERT code here (e.g. start timers, load audio, start listeners, etc.)
end
– Called when scene is about to move offscreen:
function scene:exitScene( event )
local group = self.view
Runtime:removeEventListener(“enterFrame”, emperor)
ads.hide()
storyboard.purgeScene(storyboard.getCurrentSceneName())
– INSERT code here (e.g. stop timers, remove listenets, unload sounds, etc.)
end
– If scene’s view is removed, scene:destroyScene() will be called just prior to:
function scene:destroyScene( event )
local group = self.view
end
– END OF YOUR IMPLEMENTATION
– “createScene” event is dispatched if scene’s view does not exist
scene:addEventListener( “createScene”, scene )
– “enterScene” event is dispatched whenever scene transition has finished
scene:addEventListener( “enterScene”, scene )
– “exitScene” event is dispatched whenever before next scene’s transition begins
scene:addEventListener( “exitScene”, scene )
– “destroyScene” event is dispatched before view is unloaded, which can be
– automatically unloaded in low memory situations, or explicitly via a call to
– storyboard.purgeScene() or storyboard.removeScene().
scene:addEventListener( “destroyScene”, scene )
return scene
[/lua]