Object in front of map

Hello everybody, I would like to create a short loading screen to hide the map while it’s loading.

You can see the map loading on this video, just after the 1-3 screen, and it’s really ugly.

https://www.youtube.com/watch?v=hepPxdS1YPA

That’s why I would like to put a black rectangle to hide the entire screen.

What I did :

loadingBackground = display.newRect(0, 0, display.contentWidth, display.contentHeight) loadingBackground.x = display.contentWidth/2 loadingBackground.y = display.contentHeight/2 loadingBackground:setFillColor(0, 0, 0) mte.loadMap(mappath.."level"..levelNum..".tmx") -- load our map loadingBackground:toFront() mte.setCamera({cullingMargin = {96,16,96,16}}) loadingBackground:toFront() mte.constrainCamera({}) -- limit the camera movement to map's bounds loadingBackground:toFront() mte.zoom(3,1) loadingBackground.isVisible = false

But the rectangle doesn’t even show, like it never existed.

Any ideas ? Thank you in advance.

Just a quick glance I am assuming its because of:

loadingBackground.isVisible = false you set it to not show.

Looks like you did that just to set it to invisible when not loading anymore, try:

timer.performWithDelay( 1500, function() loadingBackground:removeSelf() loadingBackground = nil end, 1 )

which just cleans out the loading screen after a certain time period. Also calling loadingBackground:toFront() all the time isn’t needed just could easily create the loading screen as the last thing on the list or after the map etc ( that way it’s on the top of display), and that above code should clean it out.

EDIT: btw your game is looking nice, nice to see where its going! That dialog box and text scrolling is pretty sweet! Wish i had that text scrolling dialog lol.

Thank you for the fast reply, Azmar ! 

Even if I remove the isVisible=false line, I still don’t see the rectangle. And I put toFront()'s everywhere because I’m really desperate, I still don’t see the rectangle ! Well, I see it, but it’s in the foreground, so the map is on top of the rectangle.

And thanks about the RPG dialog, I’m sure you could create one also, it’s quite easy as you just have to display the text character-by-character and cut it for multiple windows  :stuck_out_tongue:

EDIT : OK I finally got it ! I had to put loadingBackground.isVisible = false in the “did” event of scene:show (composer) and the isVisible = true in the scene:create function ! Thank you for your help again.

Display object are OpenGL which cannot sit on top of native objects like maps or text fields. You may be able to hide the native objects but can’t place them behind display objects.

Just a quick glance I am assuming its because of:

loadingBackground.isVisible = false you set it to not show.

Looks like you did that just to set it to invisible when not loading anymore, try:

timer.performWithDelay( 1500, function() loadingBackground:removeSelf() loadingBackground = nil end, 1 )

which just cleans out the loading screen after a certain time period. Also calling loadingBackground:toFront() all the time isn’t needed just could easily create the loading screen as the last thing on the list or after the map etc ( that way it’s on the top of display), and that above code should clean it out.

EDIT: btw your game is looking nice, nice to see where its going! That dialog box and text scrolling is pretty sweet! Wish i had that text scrolling dialog lol.

Thank you for the fast reply, Azmar ! 

Even if I remove the isVisible=false line, I still don’t see the rectangle. And I put toFront()'s everywhere because I’m really desperate, I still don’t see the rectangle ! Well, I see it, but it’s in the foreground, so the map is on top of the rectangle.

And thanks about the RPG dialog, I’m sure you could create one also, it’s quite easy as you just have to display the text character-by-character and cut it for multiple windows  :stuck_out_tongue:

EDIT : OK I finally got it ! I had to put loadingBackground.isVisible = false in the “did” event of scene:show (composer) and the isVisible = true in the scene:create function ! Thank you for your help again.

Display object are OpenGL which cannot sit on top of native objects like maps or text fields. You may be able to hide the native objects but can’t place them behind display objects.