I am a newbie and I was playing around with the shape function.However,my shape does not show as what i intended and seemed like the simulator has not fully show all its screen.Can someone help me?
Hi @counter1835,
I think you’ll need to show your code for this, so the community/staff knows what you’ve done. Please remember to wrap the code in “lua” tags for clarity in the forums:
[lua] -- code [/lua]
Thanks,
Brent
Here is the code.
[lua]
local rect = display.newRect(110,100,250,250)
rect:setFillColor(255,255,255)
rect:setStrokeColor(45,180,100)
rect.strokeWidth = 10
[/lua]
Hi @counter1835,
Does your project have a “config.lua” file inside the main root folder? If so, can you post the contents of that file?
No, I dont have.I just follow the tutorial from a book.
Hello @counter1835,
I suggest that you create a new “Blank” project from the Corona Simulator. This option is under “File > New Project”. Doing so will give you the basic file(s) that should be included in all Corona projects.
Sincerely,
Brent Sorrentino
local rect = display.newRect(110,100,250,250) rect:setFillColor(255,255,255) rect:setStrokeColor(45,180,100) rect.strokeWidth = 10
Your code is apparently from an older pre-Graphics 2.0 tutorial. I can tell this because we no longer use color ranges of 0…255, but 0…1. In Graphics 1, the first two values to display.newRect() was the x, y location of the “top left” corner. In graphics 1.0, you would end up with a white block starting at 110, 110 that was 250x250 points. Now the x, y in display.newRect() represents the center of the square, not the top left. In your case, a 250 wide image centered on 110, will have part of the square off screen which is what you’re getting. If you want it to behave where the top left corner is at 110, 110 you have two choices:
local rect = display.newRect(110 + 125, 100 + 125, 250, 250) rect:setFillColor(1, 1, 1) rect:setStrokeColor(45 / 255, 180 / 255, 100 / 255) rect.strokeWidth = 10
This version adds half the width of the box to the x, y points to center at the right place. I personally wouldn’t do the math like that, I would instead use the values of 235 and 225 and get your mind around that your centering the box instead of using the top left.
Or you can use anchor points to change what x, y means:
local rect = display.newRect(110,100,250,250) rect.anchorX = 0 rect.anchorY = 0 rect:setFillColor( 1, 1, 1) rect:setStrokeColor(45 / 255, 180 / 255, 100 / 255) rect.strokeWidth = 10
Anchor points range from 0 … 1. 0 for X means the left edge, 0.5 center and 1 the right edge. On the Y side, 0 is top, 0.5 is center and 1 is bottom. In this case, 110, 100 would now be the top left corner instead of center.
You should still start with a project like Brent suggested.
Hope this helps
Rob
Thank you , dear Brent and Rob! I have learnt a lot from you guys! The tips works like charm!
Hi @counter1835,
I think you’ll need to show your code for this, so the community/staff knows what you’ve done. Please remember to wrap the code in “lua” tags for clarity in the forums:
[lua] -- code [/lua]
Thanks,
Brent
Here is the code.
[lua]
local rect = display.newRect(110,100,250,250)
rect:setFillColor(255,255,255)
rect:setStrokeColor(45,180,100)
rect.strokeWidth = 10
[/lua]
Hi @counter1835,
Does your project have a “config.lua” file inside the main root folder? If so, can you post the contents of that file?
No, I dont have.I just follow the tutorial from a book.
Hello @counter1835,
I suggest that you create a new “Blank” project from the Corona Simulator. This option is under “File > New Project”. Doing so will give you the basic file(s) that should be included in all Corona projects.
Sincerely,
Brent Sorrentino
local rect = display.newRect(110,100,250,250) rect:setFillColor(255,255,255) rect:setStrokeColor(45,180,100) rect.strokeWidth = 10
Your code is apparently from an older pre-Graphics 2.0 tutorial. I can tell this because we no longer use color ranges of 0…255, but 0…1. In Graphics 1, the first two values to display.newRect() was the x, y location of the “top left” corner. In graphics 1.0, you would end up with a white block starting at 110, 110 that was 250x250 points. Now the x, y in display.newRect() represents the center of the square, not the top left. In your case, a 250 wide image centered on 110, will have part of the square off screen which is what you’re getting. If you want it to behave where the top left corner is at 110, 110 you have two choices:
local rect = display.newRect(110 + 125, 100 + 125, 250, 250) rect:setFillColor(1, 1, 1) rect:setStrokeColor(45 / 255, 180 / 255, 100 / 255) rect.strokeWidth = 10
This version adds half the width of the box to the x, y points to center at the right place. I personally wouldn’t do the math like that, I would instead use the values of 235 and 225 and get your mind around that your centering the box instead of using the top left.
Or you can use anchor points to change what x, y means:
local rect = display.newRect(110,100,250,250) rect.anchorX = 0 rect.anchorY = 0 rect:setFillColor( 1, 1, 1) rect:setStrokeColor(45 / 255, 180 / 255, 100 / 255) rect.strokeWidth = 10
Anchor points range from 0 … 1. 0 for X means the left edge, 0.5 center and 1 the right edge. On the Y side, 0 is top, 0.5 is center and 1 is bottom. In this case, 110, 100 would now be the top left corner instead of center.
You should still start with a project like Brent suggested.
Hope this helps
Rob
Thank you , dear Brent and Rob! I have learnt a lot from you guys! The tips works like charm!