Regarding newImageRect.

Hi,

I finally could get newImageRect to show image fullscreen on the simulator with manually changing it’s x and y and setting it to half of display.contentHeight and display.contentWidht respectfully.

My question is, am I doing the right thing here? Because setting it’s x and y manually is awkward because I believe default anchor point is top left for display images. And besides, background:setReferencePoint(display.CenterReferencePoint);

doesn’t seem to affect it.

My whole code to load a background in multi-resolutions:

local _H = display.contentHeight;
local _W = display.contentWidth;

local background = display.newImageRect(“background.png”,_W,_H);
–background:setReferencePoint(display.CenterReferencePoint);
background.x = _W/2; background.y = _H/2

and I would like to know if we have to set x and y for that object or there is a better setting to do somewhere to fix this automatically. I tried:

xAlign = “left”,
yAlign = “top”,

in config.lua, but that didn’t solve this.

Thanks! [import]uid: 206803 topic_id: 34397 reply_id: 334397[/import]

I use this approach:

 local background = display.newImageRect( "images/bkgd.png", 570, 380 )  
 background:setReferencePoint( display.CenterReferencePoint )  
 background.x = display.contentCenterX  
 background.y = display.contentCenterY  
  

with this in config:

xAlign = "center", yAlign = "center", [import]uid: 186251 topic_id: 34397 reply_id: 136691[/import]

display.newImageRect() does not specify an X, Y, but a width and height. If you do not set the X, Y for the image, it will be loaded at 0,0 which will have half of it off screen to the top and half off screen to the left since the center of the image is the reference point.

If you want that image centered you simply do:

local background = display.newImageRect( “images/bkgd.png”, 570, 380 )
background.x = display.contentCenterX
background.y = display.contentCenterY

Now there is magic going on behind the scene. The height and width of the image above is 570 wide and 380 high. Your config.lua is probably 480 x 320 which means part of this image will be off screen and that’s okay. But if you don’t set the X, Y, it will be centered on 0,0.

If you have a higher resolution screen, Corona SDK will either scale the image up until it fits, or if your config.lua is setup to use multiple resolutions, then it will look to find higher resolution images and use them, scaling them up until it finds the next higher resolution image.
[import]uid: 199310 topic_id: 34397 reply_id: 136737[/import]

I use this approach:

 local background = display.newImageRect( "images/bkgd.png", 570, 380 )  
 background:setReferencePoint( display.CenterReferencePoint )  
 background.x = display.contentCenterX  
 background.y = display.contentCenterY  
  

with this in config:

xAlign = "center", yAlign = "center", [import]uid: 186251 topic_id: 34397 reply_id: 136691[/import]

display.newImageRect() does not specify an X, Y, but a width and height. If you do not set the X, Y for the image, it will be loaded at 0,0 which will have half of it off screen to the top and half off screen to the left since the center of the image is the reference point.

If you want that image centered you simply do:

local background = display.newImageRect( “images/bkgd.png”, 570, 380 )
background.x = display.contentCenterX
background.y = display.contentCenterY

Now there is magic going on behind the scene. The height and width of the image above is 570 wide and 380 high. Your config.lua is probably 480 x 320 which means part of this image will be off screen and that’s okay. But if you don’t set the X, Y, it will be centered on 0,0.

If you have a higher resolution screen, Corona SDK will either scale the image up until it fits, or if your config.lua is setup to use multiple resolutions, then it will look to find higher resolution images and use them, scaling them up until it finds the next higher resolution image.
[import]uid: 199310 topic_id: 34397 reply_id: 136737[/import]