anchor command use

hii ,

i am new to corona .i write a simpe code but my anchor command doesnot seem to work like i supposed

local background=display.newImageRect("path3338.png",display.contentWidth,200) background.anchorX=0 background.anchorY=0 background.x=0 background.y=0

i supposed my image would display with their left top corner matches with origin ,but my image is not showing at all. 

Hmm… I looked at your code again and I’m not clear why you are not seeing the image.

Be sure the image file exists and has matching case.

I can tell you that assuming <0,0> is the upper-left corner is wrong.  It depends on your config.lua settings and the device you are on.  

You may want to look at my simple edge discovery example:

https://github.com/roaminggamer/RG_FreeStuff/tree/master/AskEd/2015/10/lgg4

lgg4.png

here is my config file

application = { content = { width = 1024, height = 768, scale = "zoomEven", fps = 30, --[[imageSuffix = { ["@2x"] = 2, ["@4x"] = 4, }, --]] }, }

the default option was letterBox but it showed some black area around my image also then i changed it to zoomEven  .three images

with letterBox option ,zoomeven option and main.lua file are here.

and if the coordinates i choose differ with different resolution phones, so how can i choose a common coordinates,width and height of objects which will perfectly work with every device…

From documentation

The content area should always be defined in respect to portrait orientation. If your app is designed for landscape orientation, you should still set the width and height according to portrait orientation. In the example above, a landscape-oriented app should still use width and heightparameters of 320 and 480 respectively, not 480 and 320.

“zoomEven” — scales the content area to fill the screen while preserving the same aspect ratio. Some content may “bleed” off the screen edges on devices with aspect ratios that differ from your content aspect ratio.

So I recommended replace width value with height value. Code below 

application = { &nbsp;&nbsp;&nbsp;&nbsp;content = &nbsp;&nbsp;&nbsp;&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;width =&nbsp;768, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;height = 1024 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scale = "zoomEven", &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fps = 30, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--[[&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;imageSuffix = &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ["@2x"] = 2, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ["@4x"] = 4, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--]] &nbsp;&nbsp;&nbsp;&nbsp;}, }

You can still get (0,0) not in left top corner of screen with zoomEven mode. Maybe try 

local aspectRatio = display.pixelHeight / display.pixelWidth application = { &nbsp; &nbsp;content = { &nbsp; &nbsp; &nbsp; width = aspectRatio \>= 1.5 and 800 or math.floor( 1200 / aspectRatio ), &nbsp; &nbsp; &nbsp; height = aspectRatio \<= 1.5 and 1200 or math.floor( 800 \* aspectRatio ), &nbsp; &nbsp; &nbsp; scale = "letterBox", &nbsp; &nbsp; &nbsp; fps = 30, &nbsp; &nbsp; &nbsp; imageSuffix = { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;["@2x"] = 1.3, &nbsp; &nbsp; &nbsp; }, &nbsp; &nbsp;}, }

Read more from Tutorial: Modernizing the config.lua

thanks all of you,

Hmm… I looked at your code again and I’m not clear why you are not seeing the image.

Be sure the image file exists and has matching case.

I can tell you that assuming <0,0> is the upper-left corner is wrong.  It depends on your config.lua settings and the device you are on.  

You may want to look at my simple edge discovery example:

https://github.com/roaminggamer/RG_FreeStuff/tree/master/AskEd/2015/10/lgg4

lgg4.png

here is my config file

application = { content = { width = 1024, height = 768, scale = "zoomEven", fps = 30, --[[imageSuffix = { ["@2x"] = 2, ["@4x"] = 4, }, --]] }, }

the default option was letterBox but it showed some black area around my image also then i changed it to zoomEven  .three images

with letterBox option ,zoomeven option and main.lua file are here.

and if the coordinates i choose differ with different resolution phones, so how can i choose a common coordinates,width and height of objects which will perfectly work with every device…

From documentation

The content area should always be defined in respect to portrait orientation. If your app is designed for landscape orientation, you should still set the width and height according to portrait orientation. In the example above, a landscape-oriented app should still use width and heightparameters of 320 and 480 respectively, not 480 and 320.

“zoomEven” — scales the content area to fill the screen while preserving the same aspect ratio. Some content may “bleed” off the screen edges on devices with aspect ratios that differ from your content aspect ratio.

So I recommended replace width value with height value. Code below 

application = { &nbsp;&nbsp;&nbsp;&nbsp;content = &nbsp;&nbsp;&nbsp;&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;width =&nbsp;768, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;height = 1024 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;scale = "zoomEven", &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fps = 30, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--[[&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;imageSuffix = &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ["@2x"] = 2, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ["@4x"] = 4, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--]] &nbsp;&nbsp;&nbsp;&nbsp;}, }

You can still get (0,0) not in left top corner of screen with zoomEven mode. Maybe try 

local aspectRatio = display.pixelHeight / display.pixelWidth application = { &nbsp; &nbsp;content = { &nbsp; &nbsp; &nbsp; width = aspectRatio \>= 1.5 and 800 or math.floor( 1200 / aspectRatio ), &nbsp; &nbsp; &nbsp; height = aspectRatio \<= 1.5 and 1200 or math.floor( 800 \* aspectRatio ), &nbsp; &nbsp; &nbsp; scale = "letterBox", &nbsp; &nbsp; &nbsp; fps = 30, &nbsp; &nbsp; &nbsp; imageSuffix = { &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;["@2x"] = 1.3, &nbsp; &nbsp; &nbsp; }, &nbsp; &nbsp;}, }

Read more from Tutorial: Modernizing the config.lua

thanks all of you,