Please help - creating rectangle with display.rewRect( )

Hi guys,
 
I just started Corona SDK and tried to create a rectangle using this code:

local myRec = display.newRect(10, 100, 200, 200)

but the code doesn’t work as it support to. The first two params are for X and Y of top left corner of rectangle. So in this case, the top left corner should be 10 pixel to left, and 100 pixel down. But please see screenshot I attached, it’s not the way it should be. 

Should I change anything in my setting? I am using Lua Glider as my editor. 

Also, why the Width and Height is not 200 px ?   this should be so simple but please help me what is wrong with  this code I am missing something??

Thank you so much

x and y is the center of the rect

Thanks for your quick reply, I changed my code and it’s now working fine. But why in the API doc page, it says the X and Y are for top left corner of rectangle? it’s strange, maybe I didn’t get it correctly.

Here is the API :  http://docs.coronalabs.com/api/library/display/newRect.html

API says: … Creates a rectangle [RectObject][api.type.RectObject] with the top-left corner position specified by left and top arguments.

here is my new code :

local x = display.contentCenterX local y = display.contentCenterY local rec = display.newRect(x, y, 320, 480) rec:setFillColor(186, 27, 27) -- this should change the rec color, but it doesn't

In the last line, I tried to change the rec color but it is still in white color  ! 

I attached screenshot.

Thanks in advanced :slight_smile:

doc hasn’t been updated for graphics 2.0
in graphics 2.0 all new objects are created with center anchor point
http://docs.coronalabs.com/guide/graphics/transform-anchor.html

color is now a value from 0 - 1 not 0-255

heres a guide for graphics 2.0
http://docs.coronalabs.com/guide/graphics/migration.html

Thank you jstrahan for your reply.

In the link you gave me, in section for setting the colors it says:


Color Definition:

For properties like object:setFillColor() and object:setStrokeColor(), RGBA color settings range between 0.0 and 1.0, not between 0 and 255. In addition, APIs that were available in Graphics 1.0 will adopt the new range by default, unless you enable V1 Compatibility Mode.


What is " V1 Compatibility Mode"  ? How can I enale it ?

Thank you in advanced.

@andy.tech: To activate it, add graphicsCompatibility = 1 to your config.lua file

http://docs.coronalabs.com/guide/graphics/migration_v1.html

since your just starting to learn how to use corona I wouldn’t worry bout using v1 since it will not be used by corona anymore

Thank you Max84 for a quick reply , I also found this article in Corona blog very helpful

http://coronalabs.com/blog/2013/10/16/wednesday-faqs-graphics-2-0/

Andy

x and y is the center of the rect

Thanks for your quick reply, I changed my code and it’s now working fine. But why in the API doc page, it says the X and Y are for top left corner of rectangle? it’s strange, maybe I didn’t get it correctly.

Here is the API :  http://docs.coronalabs.com/api/library/display/newRect.html

API says: … Creates a rectangle [RectObject][api.type.RectObject] with the top-left corner position specified by left and top arguments.

here is my new code :

local x = display.contentCenterX local y = display.contentCenterY local rec = display.newRect(x, y, 320, 480) rec:setFillColor(186, 27, 27) -- this should change the rec color, but it doesn't

In the last line, I tried to change the rec color but it is still in white color  ! 

I attached screenshot.

Thanks in advanced :slight_smile:

doc hasn’t been updated for graphics 2.0
in graphics 2.0 all new objects are created with center anchor point
http://docs.coronalabs.com/guide/graphics/transform-anchor.html

color is now a value from 0 - 1 not 0-255

heres a guide for graphics 2.0
http://docs.coronalabs.com/guide/graphics/migration.html

Thank you jstrahan for your reply.

In the link you gave me, in section for setting the colors it says:


Color Definition:

For properties like object:setFillColor() and object:setStrokeColor(), RGBA color settings range between 0.0 and 1.0, not between 0 and 255. In addition, APIs that were available in Graphics 1.0 will adopt the new range by default, unless you enable V1 Compatibility Mode.


What is " V1 Compatibility Mode"  ? How can I enale it ?

Thank you in advanced.

@andy.tech: To activate it, add graphicsCompatibility = 1 to your config.lua file

http://docs.coronalabs.com/guide/graphics/migration_v1.html

since your just starting to learn how to use corona I wouldn’t worry bout using v1 since it will not be used by corona anymore

Thank you Max84 for a quick reply , I also found this article in Corona blog very helpful

http://coronalabs.com/blog/2013/10/16/wednesday-faqs-graphics-2-0/

Andy