Using newImageRect and UI.NEWBUTTON

Hey guys,
I am trying to rebuild my game for ipad using twice the resolution images, i have alot of buttons in my game using the ui library. Im trying to figure out how i can specify the dimensions for the images i use in the ui buttons. here is what im trying but it gives me an error.

1
2
3
4
5
6
local buttonGraphic = display.newImageRect("challenges_text_btn.png", 164, 42)
challengesText = ui.newButton{
                                        default = buttonGraphic,
                                        onEvent = challengeMakeReady,
                                        id = "challengebutton"
}

Hi rxmarccall, here's how I do my button. This one is an icon based button. btnPlayAgain.png is normal state, while btnPlayAgainOver.png is what it looks like when a user presses on the button. I hope this helps.

Naomi

1
2
3
4
5
6
7
8
9
10
        imgWidth = 50;
        imgHeight = 50;
        btn_playAgain = ui.newButton{
                defaultSrc = "PNG/btnPlayAgain.png", defaultX = imgWidth, defaultY = imgHeight,
                overSrc = "PNG/btnPlayAgainOver.png", overX = imgWidth, overY = imgHeight,
                onRelease = playAgain
        }
        btn_playAgain.x = 245;
        btn_playAgain.y = 25;
        localGroup:insert(btn_playAgain);

Yea well see normally i can just create a button like so

1
2
3
4
5
challengesText = ui.newButton{
                                        default = "mygraphic.png",
                                        onEvent = challengeMakeReady,
                                        id = "challengebutton"
}

I think you need to specify defaultX and defaultY. defaultX & defaultY sound like the x,y coordinate (i.e., position of the button), but it actually is the size of the button you specify. Same is true iwth overX and overY. Try adding them and see how it works. As for the positioning of the button, you use myButton.x and myButton.y after the button is made.

By the way, have you looked into dynamic image resolution? I build for iPhone (3.1.3), iPhone3G (4.2.1), iPhone3GS (4.3.5), iPhone4 (4.3.5 or 4.2.10), iPhone4S (5.0) and iPad without changing my code at all. All I have is the imageSuffix in config.lua set to ["@2x"] = 2, and I supply two sets of graphic files (like so, myButton.png and myButton@2x.png). When my game runs on a higher resolution device, it will display the image with @2x instead of the ones without.

Naomi

EDIT: The more I thought about your case, I think all you have to do is to configure your config.lua properly, and then add @2x image files. Once you do that, you may not need to change your code at all (if your original version was built for iOS and not Android).

So turns out i was using the ui.lua v1.5 library, i updated to the 2.4 and now i can use the defaultX and defaultY, and that did the trick for me... thanks for your help

Glad to hear it worked out for you.

Naomi

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