[Resolved] Problem implementing scrolling (for credits)

So I added some credits to my app, and decided to make them scroll, like a film.

Here is the code I am using for that:
[lua]function displayCredits()
display.remove( menuGroup )
– Unload the menu content

audio.stop( playSndWelcome )

blockLogo = display.newImageRect( “black.png”, display.contentWidth, 160 )
blockLogo:setReferencePoint( display.TopLeftReferencePoint )
blockLogo.x = 0
blockLogo.y = 0

blockButton = display.newRect( 0, 410, display.contentWidth, 70 )
blockButton:setFillColor( 0, 0, 0 )

creditsHeader1 = display.newText( “game concept and design”, 0, 0, “MyFont-Bold”, 20 )
creditsHeader1:setReferencePoint( display.TopCenterReferencePoint )

creditsText1 = display.newText( “XXX”, 0, 0, “MyFont-Regular”, 20 )
creditsText1:setReferencePoint( display.TopCenterReferencePoint )

creditsHeader2 = display.newText( “game programming”, 0, 0, “MyFont-Bold”, 20 )
creditsHeader2:setReferencePoint( display.TopCenterReferencePoint )

creditsText2 = display.newText( “XXX”, 0, 0, “MyFont-Regular”, 20 )
creditsText2:setReferencePoint( display.TopCenterReferencePoint )

creditsHeader3 = display.newText( “art design”, 0, 0, “MyFont-Bold”, 20 )
creditsHeader3:setReferencePoint( display.TopCenterReferencePoint )

creditsText3 = display.newText( “XXX”, 0, 0, “MyFont-Regular”, 20 )
creditsText3:setReferencePoint( display.TopCenterReferencePoint )

creditsHeader4 = display.newText( “music”, 0, 0, “MyFont-Bold”, 20 )
creditsHeader4:setReferencePoint( display.TopCenterReferencePoint )

creditsText4 = display.newText( “XXX”, 0, 0, “MyFont-Regular”, 20 )
creditsText4:setReferencePoint( display.TopCenterReferencePoint )

creditsHeader5 = display.newText( “sound effects”, 0, 0, “MyFont-Bold”, 20 )
creditsHeader5:setReferencePoint( display.TopCenterReferencePoint )

creditsText5 = display.newText( “XXX”, 0, 0, “MyFont-Regular”, 20 )
creditsText5:setReferencePoint( display.TopCenterReferencePoint )

local function backToMenu()
display.remove( creditsGroup )
– Unload the credits content

displayMenu()
– Show the menu screen
end

buttonBackMenu = ui.newButton{
defaultSrc = “ui-button.png”,
defaultX = 220,
defaultY = 30,
overSrc = “ui-button_clicked.png”,
overX = 220,
overY = 30,
onRelease = backToMenu,
id = “buttonBackMenu”,
text = “Main Menu”,
font = “MyFont-Regular”,
size = 16,
emboss = true
}

buttonBackMenu.x = display.contentWidth/2
buttonBackMenu.y = 440

creditsGroup = display.newGroup()
creditsGroup:insert(creditsHeader1)
creditsGroup:insert(creditsText1)
creditsGroup:insert(creditsHeader2)
creditsGroup:insert(creditsText2)
creditsGroup:insert(creditsHeader3)
creditsGroup:insert(creditsText3)
creditsGroup:insert(creditsHeader4)
creditsGroup:insert(creditsText4)
creditsGroup:insert(creditsHeader5)
creditsGroup:insert(creditsText5)
creditsGroup:insert(blockLogo)
creditsGroup:insert(blockButton)
creditsGroup:insert(buttonBackMenu)

local function scrollCredits()
creditsHeader1.x = display.contentWidth/2
creditsHeader1.y = display.contentHeight
creditsText1.x = display.contentWidth/2
creditsText1.y = display.contentHeight + 25
creditsHeader2.x = display.contentWidth/2
creditsHeader2.y = display.contentHeight + 70
creditsText2.x = display.contentWidth/2
creditsText2.y = display.contentHeight + 95
creditsHeader3.x = display.contentWidth/2
creditsHeader3.y = display.contentHeight + 140
creditsText3.x = display.contentWidth/2
creditsText3.y = display.contentHeight + 165
creditsHeader4.x = display.contentWidth/2
creditsHeader4.y = display.contentHeight + 210
creditsText4.x = display.contentWidth/2
creditsText4.y = display.contentHeight + 235
creditsHeader5.x = display.contentWidth/2
creditsHeader5.y = display.contentHeight + 280
creditsText5.x = display.contentWidth/2
creditsText5.y = display.contentHeight + 305

transition.to( creditsHeader1, { time=15000, y=-185 } );
transition.to( creditsText1, { time=15000, y=-160 } );
transition.to( creditsHeader2, { time=15000, y=-115 } );
transition.to( creditsText2, { time=15000, y=-90 } );
transition.to( creditsHeader3, { time=15000, y=-45 } );
transition.to( creditsText3, { time=15000, y=-20 } );
transition.to( creditsHeader4, { time=15000, y=25 } );
transition.to( creditsText4, { time=15000, y=50 } );
transition.to( creditsHeader5, { time=15000, y=95 } );
transition.to( creditsText5, { time=15000, y=120, onComplete=scrollCredits } );
end

scrollCredits()
end[/lua]

When I go to the credits screen, everything works fine. The text scrolls as it should, scrolls off the screen, starts again. Everything is good.

If I click the Main Menu button and go back to the menu, then click the Credits button again, the Credits screen starts working fine, with the text scrolling, then the text just disappears and it starts again at the starting point. Text starts scrolling and then it disappears at a different point, and starts again from the start point.

Why is this happening? Why does going to the menu and coming back cause the scrolling to stop working correctly?
[import]uid: 17827 topic_id: 25808 reply_id: 325808[/import]

Without dissecting your code, I sense some possible issues.

First, you should cancel the transitions when you leave the scene. Remember that when you remove the group from the screen, it’s just removing the visual aspect of them. The objects still exist in memory, because you don’t “nil” them out, and the transitions are locking them into memory so the Lua garbage collector can’t clean them up (at least not immediately).

Second, wouldn’t it be easier to just transition the entire group you’ve placed all of the credits items into? You can transition a display group just like a display object.

Either way, cancel the transition(s) when you exit. :slight_smile: If you don’t, they can pile up in a big mess and overlap each other, causing major problems (I suspect what you’re seeing in our current code).

Hope that helps,

Brent Sorrentino
Ignis Design [import]uid: 9747 topic_id: 25808 reply_id: 104349[/import]

Brent,
Thank you. That was it.

The reason that I wasn’t transitioning the group was that I wasn’t able to get that to work when I tried it originally. I tried again and got it working, and then through a lot of fiddling with the reference points, I for it all working.

Appreciate the quick response. [import]uid: 17827 topic_id: 25808 reply_id: 104353[/import]