image size help

I am using director for level transitions but the sizes of the level backgrounds are all off. Whatever I try doesn't seem to change anything. What is the best way to change the background size to fit the screen. Thanks.

I fixed that problem, but the buttons are behind the background. How do I fix this?

Change the order in the file.
A file is executed linearly so whatever you run last in the code will show up on top of others (closer to the user).
In your case, place the part to create background first (top of the code) than the buttons.

You can also use myButton:toFront() -- it's a pretty useful function.

Cheers,
Naomi

thanks! I'll give those a try

thats odd, the button is after the background but still showing up behind it. It doesn't seem to be responding to the toFront either

That sounds strange. Do you have your buttons set to visible? (i.e., isVisible = true, and alpha = 1) Also, are you sure they are behind the background? And, if they are behind the background, how do you know if they are even there? Is your background actually transparent, and you are seeing the buttons? Not sure what to think...

Naomi

the buttons do work and when I was experimenting with the background I saw the button when the background was offcenter. I'm not sure if they are sent to visible, is that needed?

Hey, shakmbakm, if you never set the button's isVisible property to false, I don't think you need to set it. Same goes true with the alpha property. At this point, I have no idea what might be your problem. Maybe you need to post some code, and cross your fingers for someone to come by and help you out.

Naomi

Have you added the background and buttons to display groups? If so, and they are in different display groups, the order of those groups matter too. Make sure that whatever display group the buttons are in is inserted after the display group the background is in.

Does that make sense to you?

Yeah the buttons are currently after the background. I'll show some code here.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
 function new()
        local localGroup = display.newGroup()
        
        local background = display.newImage('titleNoButtons.png', true)
        background:scale(display.contentWidth/640, display.contentHeight/960)
        background:setReferencePoint(display.TopLeftReferencePoint)
        
        background:toBack()
 
        local startButton = display.newImage('newGame.png',true)
        startButton:toFront()
        startButton.x = 230
        startButton.y = 300
        startButton:setReferencePoint(display.CenterReferencePoint)
        startButton.scene = "world1Mini"

The only thing I can see wrong there is that you're not adding either of the objects to the 'localGroup' display group.

Try

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 function new()
 
        -- Creates a new display group
        local localGroup = display.newGroup()
        
        local background = display.newImage('titleNoButtons.png', true)
        background:scale(display.contentWidth/640, display.contentHeight/960)
        background:setReferencePoint(display.TopLeftReferencePoint)
        
        -- Inserts the background into the display group 1st (bottom of the display stack)
        localGroup:insert(background)
 
        local startButton = display.newImage('newGame.png',true)
        startButton:toFront()
        startButton.x = 230
        startButton.y = 300
        startButton:setReferencePoint(display.CenterReferencePoint)
        startButton.scene = "world1Mini"
 
        -- Inserts the startButton into the display group 2nd (on top of the display stack)
        localGroup:insert(startButton)

Hey, shakmbakm, when do you insert background and startButton into localGroup? The code you supplied does not show how/when you insert them. The order in which you insert these elements will make a world of difference. Also, you need to use the toBack() and toFront() after you insert them to the localGroup to make any difference.

Naomi

yeah that was it, I forgot to insert the background. Thanks everyone!

No problem. Glad you got it sorted.

views:517 update:2011/11/19 17:31:56
corona forums © 2003-2011