I have a screen that has animation on it, like a rotating gear. When I leave and go to other screens then come back the animation starts back working, which is what I want.
I just made another screen. All it has on it is a background and a backbitten. When I leave my animated screen, go to this screen and come back, my animation doesn’t work and then the screen freezes. What is in the code on this new screen that is causing a problem?
Also when I go to this screen that only has a background and a button, I get a ton of runtime errors in the terminal. where as when I go to other screens nothing. I can’t figure it out.
This is the screen with the animation
[lua]module(…, package.seeall)
function new()
local localGroup = display.newGroup()
–> This is how we start every single file or “screen” in our folder, except for main.lua
– and director.lua
–> director.lua is NEVER modified, while only one line in main.lua changes, described in that file
local ui = require(“ui”)
local menu = display.newImage (“menu.png”)
localGroup:insert(menu)
–> This sets the menu
local about = display.newImage (“about.png”)
about.x = 100
about.y = 300
about.xScale = .5
about.yScale = .5
localGroup:insert(about)
local function touchedAbout (event)
if (“ended” == event.phase) then
director:changeScene (“about”)
media.playEventSound( “click_x.caf” )
end
end
about:addEventListener (“touch”, touchedAbout)
local credits1 = display.newImage (“credits1.png”)
credits1.x = 165
credits1.y = 375
credits1.xScale = .5
credits1.yScale = .5
localGroup:insert(credits1)
local rateit = display.newImage (“rateit.png”)
rateit.x = 225
rateit.y = 300
rateit.xScale = .5
rateit.yScale = .5
localGroup:insert(rateit)
–>This places the rateit button
local function doRating(event)
if event.phase == “ended” then
local url = “itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa”
url = url … “/wa/viewContentsUserReviews?”
url = url … “type=Purple+Software&id=”
url = url … “453641732”
system.openURL(url)
end
end
rateit:addEventListener(“touch”, doRating)
–> Adds the Rate It functionality. Be sure to change the APP ID to your OWN;
local brain = display.newImage (“brain.png”)
brain.x = 155
brain.y = 185
brain.xScale = .6
brain.yScale = .6
localGroup:insert(brain)
–>This places the brain
local function animate( event )
brain.rotation = brain.rotation + 1
end
Runtime:addEventListener( “enterFrame”, animate );
–>adds Animation to brain
– This cleanUp function will remove all listeners from the scene since
– Director can’t remove listeners itself
local cleanUp = function()
Runtime:removeEventListener(“enterFrame”, animate)
brain:removeEventListener(“touch”, touchedBrain)
about:removeEventListener (“touch”, touchedAbout)
end
local function touchedBrain (event)
if (“ended” == event.phase) then
media.playEventSound( “click_x.caf” )
director:changeScene(“titlescreen”) – director should clean up the rest
cleanUp() – Call the cleanUp function to remove what director can’t
end
end
brain:addEventListener (“touch”, touchedBrain)
–>MUST return a display.newGroup()
–> This is how we end every file except for director and main, as mentioned in my first comment
return localGroup
end[/lua]
This is the screen I’m transitioning to that causes the problems
[lua]module(…, package.seeall)
function new()
local localGroup = display.newGroup()
–> This is how we start every single file or “screen” in our folder, except for main.lua
– and director.lua
–> director.lua is NEVER modified, while only one line in main.lua changes, described in that file
local aboutBackground = display.newImage (“aboutbackground.png”)
localGroup:insert(aboutBackground)
–> This sets the titlescreen
local backbutton = display.newImage (“backbutton.png”)
backbutton.x = 50
backbutton.y = 430
backbutton.xScale = .4
backbutton.yScale = .4
localGroup:insert(backbutton)
–>This places the brain
local function touchedBackbutton (event)
if (“ended” == event.phase) then
director:changeScene (“menu”)
media.playEventSound( “click_x.caf” )
end
end
backbutton:addEventListener (“touch”, touchedBackbutton)
– This cleanUp function will remove all listeners from the scene since
– Director can’t remove listeners itself
local cleanUp = function()
backbutton:removeEventListener (“touch”, touchedBackbutton)
end
–>MUST return a display.newGroup()
–> This is how we end every file except for director and main, as mentioned in my first comment
return localGroup
end[/lua]
[import]uid: 72372 topic_id: 14274 reply_id: 314274[/import]
[import]uid: 71210 topic_id: 14274 reply_id: 52816[/import]