groups. Thought I had the hang of 'em, guess not.

2 replies [Last post]
slgilley
User offline. Last seen 17 weeks 27 min ago. Offline
Joined: 19 Feb 2010

I start with

local background = display.newImage("myscreen.png")
menuScreen:insert( background )

and later, when I no longer need or want that backgroup, I use:

menuScreen:remove(background)

So far so good.

Now I'm adding in the instruction pages. In the initial event that calls the first instruction page I do:

1
2
3
menuScreen:remove(background)
tutorialPage1 = display.newImage("tutorialPage1.png")
tutorialScreen:insert(tutorialPage1)

and add an event listener for page turns. One possibility in the event listener is that the user wants to go back to the main screen. My code sorta looks like this:

1
2
3
4
5
6
tutorialScreen:remove(tutorialPage1)
if(user wants to go back to main screen) then
                       Runtime:removeEventListener( "touch", tutorialTouch );
                       menuScreen:insert( background )
                       gotoMainMenu(event)
end

The problem is that the image described by "tutorialPage1" never goes away, and "background" never appears.

How come?

Thanks,

Sean.

Replies

slgilley
User offline. Last seen 17 weeks 27 min ago. Offline
Joined: 19 Feb 2010

Well, I still don't understand why it doesn't work. However, after scouring the forum, I finally ran across something that solved the problem.

When the user wants to go back to the main menu, I use the following code (one line added from original):

1
2
3
4
5
6
7
tutorialScreen:remove(tutorialPage1)
if(user wants to go back to main screen) then
     Runtime:removeEventListener( "touch", tutorialTouch );
     tutorialScreen.isVisible = false      <---- Added this line.
     menuScreen:insert( background )
     gotoMainMenu(event)
end

However, I still don't understand the relationship to screens/groups and what's displayed onscreen. Is there any good explanation of that somewhere?

Thanks,

Sean.

Shredder
User offline. Last seen 1 year 42 weeks ago. Offline
Joined: 21 Jan 2010

I am having some similar problems which we suspect are to do with garbage collection and elements hanging around. This is, apparently, a common problem with iPhone app and you need to almost force a item to be removed at times.

However, I can't for the life of me find the syntax to do this :-)

I have a couple of layers of buttons and images (each forming a page). I place the button images without the tap event, then turn it on when the page is shown ... then off when the page is left. All well and good. However, the buttons are being left active (I am also using removeEventListener).

Any ideas?

Cheers

Gary

Viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.