[HELP] How to scroll a text over an image (code inside)

Ciao,
yesterday I just buy my first Mac, just to try Corona.
This evening I try some code but I’m stuck, now.

All I wanna, is that some text will be scroll over an image.

This is the code that I use.

local textObject = display.newText( "Text line ONE that will be scrolling over the image", 1, 1, nil, 14 )  
textObject:setTextColor( 255,0,2 )  
local textObject1 = display.newText( "text line two", 1, 20, nil, 12 )  
textObject1:setTextColor( 55,0,255 )  
  
local backbg = display.newImage( "stanzatornano.jpg" )  
backbg.x = display.stageWidth / 2  
backbg.y = display.stageHeight - 200  
function backbg:tap( event )  
 local r = math.random( 0, 255 )  
 local g = math.random( 0, 255 )  
 local b = math.random( 0, 255 )  
  
 textObject:setTextColor( r, g, b )  
  
end  
backbg:addEventListener( "tap", backbg )  
  
local group = display.newGroup()  
group:insert ( textObject )  
group:insert ( textObject1 )  
group:insert ( backbg )  
assert( (group[1] == backbg) and (group[2] == textObject) and (group[3] == textObject1))  
  
transition.to( textObject, { time=10000, y=textObject.y+200 } )  

…and this is the error that Corona give me:

Copyright © 2009 ANSCA, Inc.
Version: 0.3
Build: 2009.06.15.1
Runtime script error
/Developer/ansca/SampleCode/HelloWorld/main.lua:34: assertion failed!
librtt: /Developer/ansca/SampleCode/HelloWorld/main.lua:34: assertion failed!
stack traceback:
[C]: ?
[C]: in function ‘assert’
/Developer/ansca/SampleCode/HelloWorld/main.lua:34: in main chunk

…any help?

Thanks
Ale [import]uid: 940 topic_id: 111 reply_id: 300111[/import]

It appears to work fine if you comment out the assert. I’m guessing you have other plans for this which is why you have the group at the bottom? [import]uid: 5 topic_id: 111 reply_id: 81[/import]

yes, it’s true, but the scrolling text goes down (under) the pics, and in my mind, I wanna that the scrolling text is over the pix :slight_smile: [import]uid: 940 topic_id: 111 reply_id: 82[/import]

Ah, right. Move the text so it gets created after the image does. Is an ordering problem, your image gets put on top of the text because it was created last. Do the same with your grouping, move the image to the top as it will get loaded first that way. I believe there’s a way to change the arrangement without moving things around like that… off hand I don’t recall what it is though. [import]uid: 5 topic_id: 111 reply_id: 83[/import]

The FollowMe sample shows how that’s done. When you touch an object, it becomes frontmost.

If you have a display object ‘t’, then the following moves t to the top:

local parent = t:getParent()
parent:insert( t )

Essentially, you are reinserting ‘t’ into its parent at the highest index (the end of the children array). See pg.46 under “group:insert()” in the API Reference and also pg. 22 under “Moving Objects Forward and Backward” in the AppGuide for more info. [import]uid: 5 topic_id: 111 reply_id: 84[/import]

Hey jjohnson,
thanks very much 4 your time.

Changing the ordering of elemets, solved the problem.

Obviusly isn’t a elegant way to do this, but it works :slight_smile:

A curiosity:
To clean the screen in white like a simple cls from a dos box I use this:

local mainBG = display.newRect(0 ,0 , 320, 480)  
mainBG:setFillColor (255,255,255)  

There is another solution?

Best
Ale [import]uid: 940 topic_id: 111 reply_id: 87[/import]

That will display a new rectangle in white on top of everything. Though you’re other objects will still be underneath it, though un-accessable to the user. If you’re not adding a whole lot, then I probably wouldn’t bother removing the objects. But if this is something thats going to get memory intensive then you can remove them. You can do something like this:

if mainBG then
mainBG.parent:remove(mainBG)
end

and that should remove the object from the screen. I may not have the syntax totally right but something a long those lines. But if you want to reference those objects later, I don’t believe you’ll be able to call them again. [import]uid: 5 topic_id: 111 reply_id: 93[/import]

Hi jjohnson,
thanks very much for the hint :slight_smile:
I just rewrite the code and now it works.

By the way, I hope to see more example for the next Corona build,
and maybe a better forum, with private message :slight_smile:

Ale
[import]uid: 940 topic_id: 111 reply_id: 112[/import]

Hello,

Could any one give me an idea how to scroll a long length of text (say 50 chars long) vertically.

Regards.
Dennis. [import]uid: 87460 topic_id: 111 reply_id: 55703[/import]