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.

[lua]local buttonGraphic = display.newImageRect(“challenges_text_btn.png”, 164, 42)
challengesText = ui.newButton{
default = buttonGraphic,
onEvent = challengeMakeReady,
id = “challengebutton”
}[/lua]

anyone know the correct way to get this working? thanks [import]uid: 19620 topic_id: 17873 reply_id: 317873[/import]

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

[lua] 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);[/lua] [import]uid: 67217 topic_id: 17873 reply_id: 68241[/import]

Yea well see normally i can just create a button like so
[lua]challengesText = ui.newButton{
default = “mygraphic.png”,
onEvent = challengeMakeReady,
id = “challengebutton”
}[/lua]

this way works fine, and the button size is just made to be whatever the “mygraphic.png” graphic size is. What im trying to do is create my button with a graphic that is twice the size of the original (for retina displays), but i still would like the button itself and its graphic to be sized down to what my traditional graphic size was… does that make sense? So im trying to find a way to pass what width and height i want the button to be [import]uid: 19620 topic_id: 17873 reply_id: 68242[/import]

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). [import]uid: 67217 topic_id: 17873 reply_id: 68243[/import]

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 [import]uid: 19620 topic_id: 17873 reply_id: 68262[/import]

Glad to hear it worked out for you.

Naomi [import]uid: 67217 topic_id: 17873 reply_id: 68265[/import]