How do you set the code so that the text appears above the image? Even though the text code is before the image, it stills appear below the button. How can I fix this? [import]uid: 30901 topic_id: 5915 reply_id: 305915[/import]
When you say “above” and “below” I’m assuming you actually mean on top of or behind and not actually above and below (along the Y axis).
What worked for me was using a display group. I added a background
first and then txt.
local scene1 = display.newGroup()
local background = display.newImage( myBG )
local text = display.newText( "Hello, World!", 0, 0, native.systemFont, 40 )
scene1:insert( background )
scene1:insert( text )
Hope that helps,
Aaron [import]uid: 27966 topic_id: 5915 reply_id: 20316[/import]
Graphics in Corona work according to the “Painter’s Algorithm”, which basically means objects get drawn from back-to-front. Generally, if you want text in front of an image, draw the image first, then the text.
If you’re using a group (and you should!) you can render things in any order, then use the group:insert() function to move things around in the group so they get painted in the correct order.
In the game I’m working on, I have a static background with dynamic sprites that move around, in front of some parts of the background and behind others. When I generate the background graphics, and I get to the point where my dynamic sprites need to go (so they’re painted in the correct order), I do:
local mySpriteLevel = myGroup.numChildren
Then, later on, when I’m creating the dynamic sprites, I do:
myNewSprite = display.newImageRect(...)
myGroup:insert(mySpriteLevel, myNewSprite)
[import]uid: 9659 topic_id: 5915 reply_id: 20808[/import]