Problem with identify (0,0) of content area

I’ve tried out the tutorial on “Hello World!” and am unable to display all the text in its entirely on the stage area (“Hell” is cut off):

local myText = display.newText( “Hello World!”, 50, 50, Arial, 60 )

My guess is (0,0) of the content area is located outside of the stage? How is the screenshot of the tutorial aligned correctly?

I’m working without the config.lua. 

What version of Corona SDK are you using?  Can you post your config.lua file?  Are there any errors in the terminal window?

Thanks

Rob

Hi Rob,

I’m using 2013.2076. I had an older version which I installed a year ago uninstalled before installing this version yesterday. After I couldn’t solve this issue, I uninstalled and reinstalled 2013.2076 again, but that didn’t solve the problem.

There wasn’t any error message in the terminal window. Here’s the config file content:

– config.lua

application =

{

    content =

    {

        width = 320,

        height = 480,

        scale = “letterbox” 

    },

}

Thanks, 

Hayden

The tutorial may be out of date. I guess you need to put left anchor: myText.anchorX = 0

Thanks Jon, this solved it. I guess display.setDefault( “anchorX”, 0 ) is pretty much mandatory?

I figured the tutorial was outdated when I got an error for display.setDefault( “textColor”, 255, 0, 0 )

:-/

Actually, setting the default anchor isn’t the answer.  Its a possible part of the answer.

In Graphics 2.0 (build numbers > 2000) there were changes to how things are positioned.  I’m pretty sure we wrote a blog post about it and the G2.0 conversion guide covered it as well. 

For display objects like display.newRect, display.newText, with Graphics 1.0, the numbers you passed in for the X, Y of where to draw the object was treated as the Top, Left of the object.  So:

local myText = display.newText( “Hello World!”, 50, 50, Arial, 60 )

Would put the top left corner of the string at 50, 50.  However, if you immediately printed the .x and .y values of myText, they would not be 50, 50, the would be the center of the string’s bounding box.  This duality of positioning (sometimes x, y means top, left, others it means center and always after the fact it means center) was confusing and inconsistent in the use of the API.  Now any time you specify an X, Y when creating an object, it represents the center of the bounding box.  Your string is being drawn at 50, 50, but that’s the center of the string, not the top left.

Previously with the Graphics 1 engine, you could position by setting the .x and .y as something other than center by using the object’s :setReferencePoint() setting.  We have gotten rid of this option in favor of anchor points.   To position an object by it’s top left, you would create the object then immediately set it’s anchor:

local myText = display.newText( “Hello World!”, 50, 50, Arial, 60 )

myText.anchorX = 0.0

myText.anchorY = 0.0

would cause Hello World to now position itself where 50, 50 was the top left of the bounding box.

Now you may need to set a bunch of things, like text strings to use a top left positioning and it’s too much work to always be manually setting the anchor points.  We provided a way for you to set the default for future object creation with:
 

display.setDefault( “anchorX”, 0 )

If you do this, then anything you create after that will be left aligned.  This may not be what you want.  Circles for instance have always been center positioned.  Doing this can break other objects.  You should only set the default while you are drawing left aligned objects, then set it back to 0.5 for other things to run correctly.

Rob

What version of Corona SDK are you using?  Can you post your config.lua file?  Are there any errors in the terminal window?

Thanks

Rob

Hi Rob,

I’m using 2013.2076. I had an older version which I installed a year ago uninstalled before installing this version yesterday. After I couldn’t solve this issue, I uninstalled and reinstalled 2013.2076 again, but that didn’t solve the problem.

There wasn’t any error message in the terminal window. Here’s the config file content:

– config.lua

application =

{

    content =

    {

        width = 320,

        height = 480,

        scale = “letterbox” 

    },

}

Thanks, 

Hayden

The tutorial may be out of date. I guess you need to put left anchor: myText.anchorX = 0

Thanks Jon, this solved it. I guess display.setDefault( “anchorX”, 0 ) is pretty much mandatory?

I figured the tutorial was outdated when I got an error for display.setDefault( “textColor”, 255, 0, 0 )

:-/

Actually, setting the default anchor isn’t the answer.  Its a possible part of the answer.

In Graphics 2.0 (build numbers > 2000) there were changes to how things are positioned.  I’m pretty sure we wrote a blog post about it and the G2.0 conversion guide covered it as well. 

For display objects like display.newRect, display.newText, with Graphics 1.0, the numbers you passed in for the X, Y of where to draw the object was treated as the Top, Left of the object.  So:

local myText = display.newText( “Hello World!”, 50, 50, Arial, 60 )

Would put the top left corner of the string at 50, 50.  However, if you immediately printed the .x and .y values of myText, they would not be 50, 50, the would be the center of the string’s bounding box.  This duality of positioning (sometimes x, y means top, left, others it means center and always after the fact it means center) was confusing and inconsistent in the use of the API.  Now any time you specify an X, Y when creating an object, it represents the center of the bounding box.  Your string is being drawn at 50, 50, but that’s the center of the string, not the top left.

Previously with the Graphics 1 engine, you could position by setting the .x and .y as something other than center by using the object’s :setReferencePoint() setting.  We have gotten rid of this option in favor of anchor points.   To position an object by it’s top left, you would create the object then immediately set it’s anchor:

local myText = display.newText( “Hello World!”, 50, 50, Arial, 60 )

myText.anchorX = 0.0

myText.anchorY = 0.0

would cause Hello World to now position itself where 50, 50 was the top left of the bounding box.

Now you may need to set a bunch of things, like text strings to use a top left positioning and it’s too much work to always be manually setting the anchor points.  We provided a way for you to set the default for future object creation with:
 

display.setDefault( “anchorX”, 0 )

If you do this, then anything you create after that will be left aligned.  This may not be what you want.  Circles for instance have always been center positioned.  Doing this can break other objects.  You should only set the default while you are drawing left aligned objects, then set it back to 0.5 for other things to run correctly.

Rob